forked from tbird20d/ttc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target-test.py
executable file
·681 lines (543 loc) · 20.6 KB
/
target-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#!/usr/bin/python
#
# target-test.py - python routine to test a target configuration under ttc
#
# Usage: target-test.py <target>
#
# To Do for target-test.py
# * make sure that no existing env. vars are set to conflict with our target
#
# BUGS:
# * failure of telnet_exec (ttc run) is not handled properly:
#
# OUTLINE:
# key: '-' means not implemented yet
# 001 make sure the target is listed
# 002 get target info and validate it
# 003 make sure you can get the kernel source
# * report on the version of the kernel source
# 004 make sure you can get the default kernel configuration
# 005 make sure you can build the kernel
# 006 make sure you can install the kernel and reboot
# 007 make sure you can change the kernel configuration
# 008 make sure you can reboot the target
# - 009 make sure that the board boots with the new kernel
# * make sure that the running kernel is the one newly built
# 010 make sure that you can copy a file to the target
# 011 make sure that you can copy a file from the target
# 012 make sure that you can execute a command on the target
# - 013 make sure that you can get an interactive console on the target
# - 014 make sure you can apply a patch to the kernel
# - 015 make sure you can compile a small program for the target
# * compile it, install it (with copy), and run it
# 016 make sure you can change the kernel command line
MAJOR_VERSION = 1
MINOR_VERSION = 0
REVISION = 0
import os, sys
import re, time, random
import commands
import ttc_test_utils
######################################
# Define some globals for this test suite
test_suite_name="TARG"
src_dir = "test-linux"
test_data_dir = "../test-data"
######################################
# Define some convenience classes and functions
def usage():
prog_name = os.path.basename(sys.argv[0])
print """Usage: %s [-h] <target>
where <target> is the name of the target to be used with
the 'ttc' command.
%s is a program to test whether the ttc tool is working properly
with a specified target. It executes several ttc commands, and
tests the results. If any tests fail, the problems should be
fixed before executing any other automated tools which use ttc.
-h show this usage help
-V show version information
""" % (prog_name, prog_name)
def test_setup(test_run):
# test run prep
print "Doing test preparation for %s tests..." % test_suite_name
# make test build dir
build_dir = "test-build/%s" % test_run.target
rcode = test_run.do_command("install -d %s" % build_dir, 1)
# set KBUILD_OUTPUT environment variable to build directory
# Use a relative path from the kernel source directory, which
# will be one dir down from here.
build_dir = "../test-build/%s" % test_run.target
os.environ["KBUILD_OUTPUT"]=build_dir
test_run.build_dir = build_dir
#############################################
# TARG-002 get target info and validate it
def test_002(test_run):
target = test_run.target
test_run.set_id("002", "get target info")
print "Running test %s..." % test_run.id
cmd = "ttc %s info" % target
(rcode, result) = test_run.do_command_result(cmd)
if rcode:
test_run.failure("Could not get info for target '%s'" % target, result)
# FIXTHIS - how to validate 'ttc info' result??
test_run.success("Retrieved info for target '%s'" % target, result)
cmd = "ttc %s info -v" % target
(rcode, result) = test_run.do_command_result(cmd)
if rcode:
test_run.failure("Could not get verbose info for target '%s'" % target, result)
# FIXTHIS - how to validate verbose information??
test_run.success("Retrieved verbose info for target", result)
cmd = "ttc %s info -n kimage" % target
(rcode, result) = test_run.do_command_result(cmd)
if rcode:
test_run.failure("Could not get kernel image name for target '%s'" % target, result)
kimage = result
# check that the kernel name is one of the 'normal' values
test_run.result_out("kernel image name is '%s'" % kimage)
if result not in ["vmlinux", "vmlinuz", "bzImage", "uImage", "cuImage.sequoia", "zImage"]:
test_run.failure("Kernel image name is unexpected")
else:
test_run.success("Kernel image name is OK")
#############################################
# TARG-003
# 003 make sure you can get the kernel source
# * report on the version of the kernel source
#
def test_003(test_run):
test_run.set_id("003", "get kernel source")
# SPECIAL - test for 'gk_marker' to avoid long delays when the
# test is re-run (which happens often during test development)
# auto-detect that kernel is already present in src_dir
# and skip the get_kernel automatically
rcode = test_run.do_command('test -f %s/gk_marker' % src_dir)
extra_data = ""
if rcode:
test_run.do_ttc("get_kernel -o %s" % src_dir, 1)
test_run.do_command('echo "get_kernel completed" >%s/gk_marker' % src_dir)
else:
extra_data = "*** Skipping get_kernel (get_kernel marker found)"
print extra_data
# check for success
# try to change to source directory
try:
os.chdir(src_dir)
except:
test_run.failure("Could not switch to kernel source directory after 'get_kernel'")
sys.exit(1)
# look for some 'normal' files at the root of the kernel source
if not os.path.isfile('MAINTAINERS') or not os.path.isfile('Kbuild'):
test_run.failure("Missing key files in kernel source directory after 'get_kernel'")
sys.exit(1)
# read Makefile, and get kernel version
makelines = open("Makefile").readlines()
version = 0
minor = 0
revision = 0
extra = ""
for line in makelines:
if not version and line.startswith('VERSION'):
version = line.split('=')[1].strip()
if not minor and line.startswith('PATCHLEVEL'):
minor = line.split('=')[1].strip()
if not revision and line.startswith('SUBLEVEL'):
revision = line.split('=')[1].strip()
if not extra and line.startswith('EXTRAVERSION'):
extra = line.split('=')[1].strip()
ver_str = "%s.%s.%s%s" % (version, minor, revision, extra)
test_run.result_out("Kernel version is %s" % ver_str)
test_run.success("Retrieved kernel source OK", extra_data)
#############################################
# TARG-004 make sure you can get the default kernel configuration
#
def test_004(test_run):
test_run.set_id("004", "get default kernel configuration")
print "Running test %s..." % test_run.id
config_filename = os.path.join(test_run.build_dir, ".config")
# first, remove old configuration, if present
if os.path.isfile(config_filename):
os.unlink(config_filename)
if os.path.isfile(config_filename):
test_run.failure("Could not remove pre-existing kernel config file from build dir.")
sys.exit(1)
# get default configuration
rcode = test_run.do_ttc("get_config", 1)
# verify that the configuration was placed in the build directory
if not os.path.isfile(config_filename):
test_run.failure("Could not get default kernel configuration for target")
sys.exit(1)
else:
test_run.success("Got default kernel configuration for target")
# FIXTHIS - should validate the the configuration has no invalid junk
# how???
#############################################
# TARG-005 make sure you can build the kernel
#
def test_005(test_run):
test_run.set_id("005", "build kernel")
print "Running test %s..." % test_run.id
skipping = 0
if skipping:
print "*** Skipping kernel build"
return
kernel_filename = os.path.join(test_run.build_dir, "vmlinux")
# remove existing kernel file, if present
if os.path.isfile(kernel_filename):
os.unlink(kernel_filename)
if os.path.isfile(kernel_filename):
test_run.failure("Could not remove pre-existing kernel image file from build dir.")
sys.exit(1)
# 4. build kernel
rcode = test_run.do_ttc("kbuild")
if rcode:
test_run.failure("Could not build kernel")
# there should be a vmlinux at root of build directory.
if not os.path.isfile(kernel_filename):
test_run.failure("No 'vmlinux' found after build")
else:
test_run.success("Found 'vmlinux' after build")
#############################################
# TARG-006 make sure you can install the kernel and reboot
#
def test_006(test_run):
test_run.set_id("006", "install kernel, reboot and run command")
print "Running test %s..." % test_run.id
# set the localversion to something unique
test_run.set_localversion()
rcode = test_run.do_ttc("kbuild")
# test to make sure localversion was built into local kernel image
id_str = test_run.kernel_id
rcode = test_run.do_command("grep %s $KBUILD_OUTPUT/vmlinux" % id_str)
if rcode:
test_run.failure("Could not build kernel with unique identifier '%s'" % id_str)
return
# install kernel
rcode = test_run.do_ttc("kinstall", 1)
if rcode:
test_run.failure("Could not install kernel")
# FIXTHIS - can't detect correct kernel installation without rebooting
# the board. This tests more than just kernel installation.
# reset the board - use strongest reboot possible
test_run.reset_target("reboot")
if test_run.check_localversion():
test_run.success("Kernel %s installed and booted on board" % test_run.kernel_id)
else:
test_run.failure("Could not verify kernel running on target board")
test_run.run_on_target("dmesg >/tmp/dmesg.boot.006")
#############################################
# TARG-007 make sure you can change the kernel configuration
#
def test_007(test_run):
test_run.set_id("007", "change kernel configuration")
print "Running test %s..." % test_run.id
rcode = test_run.do_ttc("set_config CONFIG_PRINTK_TIME=y", 1)
rcode = test_run.do_ttc("set_config CONFIG_LOG_BUF_SHIFT=17", 1)
# rcode = test_run.do_ttc("set_config CONFIG_PRESET_LPJ=%s" % lpj, 1)
(rcode, result) = test_run.do_make_oldconfig()
print result
test_run.check_config("CONFIG_PRINTK_TIME", "y")
# set the localversion to something unique
test_run.set_localversion()
rcode = test_run.do_ttc("kbuild")
# test to make sure localversion was built into local kernel image
id_str = test_run.kernel_id
rcode = test_run.do_command("grep %s $KBUILD_OUTPUT/vmlinux" % id_str)
if rcode:
test_run.failure("Could not build kernel with unique identifier '%s'" % id_str)
return
# install kernel
rcode = test_run.do_ttc("kinstall", 1)
if rcode:
test_run.failure("Could not install kernel")
# reset the board - use strongest reboot possible
test_run.reset_target("reboot")
if not test_run.check_localversion():
test_run.failure("Could not verify kernel running on target board")
# check for printk times format output
rcode, result = test_run.run_on_target("dmesg")
if rcode:
test_run.failure("Error collecting results from 'dmesg'", result)
return
result_list = result.split("\n")
# look for 3 samples
sample_locs = [4,7,11]
samples = []
printk_format_ok = 1
for i in sample_locs:
sample_line = result_list[i]
# work around busybox bug leaving leading kernel msg level tag
if re.match("\<[0-9]\>", sample_line):
sample_line = sample_line[3:]
if not re.match("\[ *[0-9]+\.[0-9]+\] ", sample_line):
printk_format_ok = 0
test_run.failure("Didn't find printk time format on dmesg line '%s'" % sample_line)
if printk_format_ok:
test_run.success("Successfully modified kernel configuration (with PRINTK_TIMES=y)")
test_run.run_on_target("dmesg >/tmp/dmesg.boot.007")
# FIXTHIS - should compare with: "/tmp/dmesg.boot.006" to make sure printk-times wasn't set before
# reset config
# get default configuration
rcode = test_run.do_ttc("get_config", 1)
# set the localversion to something unique
test_run.set_localversion()
rcode = test_run.do_ttc("kbuild")
# install kernel
rcode = test_run.do_ttc("kinstall", 1)
if rcode:
test_run.failure("Could not install kernel")
#############################################
# TARG-008 make sure you can reboot target
#
# check for two failure conditions, for both reset and reboot:
# 1) target was running, and after reset it never comes back up
# this is a case of hanging on the reset, which is common when
# a soft reset ('ttc run reboot') is used.
# 2) target was running, and it continued running despite the reset request
# This is another common case for when soft reset is used.
def test_008(test_run):
test_run.set_id("008", "reset and reboot target")
print "Running test %s..." % test_run.id
# FIXTHIS - this test assumes the target is running, on entry
print "Waiting a bit for target to accumulate uptime..."
time.sleep(40)
# get uptime
time1 = time.localtime()
rcode, result1 = test_run.run_on_target("cat /proc/uptime")
test_run.reset_target("reset")
# see if target resets
rcode = test_run.wait_for_target_to_boot()
if rcode:
test_run.failure("Target board did not reset properly")
else:
# get uptime after resetting
time2 = time.localtime()
rcode, result2 = test_run.run_on_target("cat /proc/uptime")
# parse results here
t1 = float(result1.split()[0])
t2 = float(result2.split()[0])
test_run.result_out("uptime before reset was %s, and after reset it is %s" % (t1, t2))
# check if t2 < t1 If so, the client reset
if t2 < t1:
test_run.success("Target board reset properly")
else:
test_run.failure("Target board did not reset properly")
# now test rebooting
test_run.reset_target("reboot")
rcode = test_run.wait_for_target_to_boot()
if rcode:
test_run.failure("Target board did not reboot properly")
else:
print "Waiting a bit for target to accumulate uptime..."
time.sleep(40)
# get uptime1
time1 = time.localtime()
rcode, result1 = test_run.run_on_target("cat /proc/uptime")
test_run.reset_target("reboot")
# get uptime after rebooting
time2 = time.localtime()
rcode, result2 = test_run.run_on_target("cat /proc/uptime")
# parse results here
t1 = float(result1.split()[0])
t2 = float(result2.split()[0])
test_run.result_out("uptime before reboot was %s, and after reboot it is %s" % (t1, t2))
# check if t2 < t1 If so, the client reset
# get uptime after rebooting
time2 = time.localtime()
rcode, result2 = test_run.run_on_target("uptime")
# check if t2 < t1 If so, the client rebooted
if t2 < t1:
test_run.success("Target board rebooted properly")
else:
test_run.failure("Target board did not reboot properly")
# 009 make sure that the board boots with the new kernel
# * make sure that the running kernel is the one newly built
#############################################
# TARG-010 make sure that you can copy a file to the target
#
def test_010(test_run):
test_run.set_id("010", "copy file to target")
print "Running test %s..." % test_run.id
testfile_name = "/tmp/test_010_file"
# create a test file with unique content
id_str = "unique_id=%s\n" % random.randint(1,10000)
fd = open(testfile_name, "w")
fd.write(id_str)
fd.close()
# copy file to target
rcode = test_run.do_ttc("cp %s target:%s" % (testfile_name, testfile_name))
# verify file is present on target
cmd = "cat %s" % testfile_name
rcode, result = test_run.run_on_target(cmd)
if rcode:
test_run.failure("Could not '%s' on target" % cmd)
return
print "id_str=", id_str.strip()
print "result=", result.strip()
# compare original and copied files
if result.strip() == id_str.strip():
test_run.success("File was successfully copied to target")
else:
test_run.success("File was successfully copied to target")
# clean up
os.unlink(testfile_name)
rcode, result = test_run.run_on_target("rm %s" % testfile_name)
#############################################
# TARG-011 make sure that you can copy a file from the target
#
def test_011(test_run):
test_run.set_id("011", "copy file from target")
print "Running test %s..." % test_run.id
testfile_name = "/tmp/test_011_file"
# create a test file with unique content on the target
id_str = "unique_id=%s" % random.randint(1,10000)
cmd = 'echo "%s" >%s' % (id_str, testfile_name)
rcode = test_run.run_on_target(cmd)
# copy file from the target
rcode = test_run.do_ttc("cp target:%s %s" % (testfile_name, testfile_name))
if rcode:
test_run.failure("File was not copied correctly from target. 'ttc cp...' failed.")
try:
fd = open(testfile_name, "r")
content = fd.read()
fd.close()
except:
test_run.failure("Could not read content of file read from target")
return
print "id_str=", id_str.strip()
print "content=", content.strip()
# compare original and copied files
if content.strip() == id_str.strip():
test_run.success("File was successfully copied from target")
else:
test_run.failure("Content of file copied from target was incorrect")
# clean up
os.unlink(testfile_name)
rcode, result = test_run.run_on_target("rm %s" % testfile_name)
# 012 make sure that you can execute a command on the target
# 013 make sure that you can get an interactive console on the target
# 014 make sure you can apply a patch to the kernel
# 015 make sure you can compile a small program for the target
# * compile it, install it (with copy), and run it
#############################################
# TARG-016 make sure that you can change the kernel command line
#
def test_016(test_run):
test_run.set_id("016", "change kernel command line")
print "Running test %s..." % test_run.id
rcode = test_run.do_ttc("get_config")
if rcode:
test_run.failure("Could not get default config")
return
# try to set CONFIG_CMDLINE_BOOL (required on x86 to set CONFIG_CMDLINE)
# don't fail if it's missing.
rcode = test_run.do_ttc('set_config CONFIG_CMDLINE_BOOL=Y', 0)
rcode = test_run.do_ttc('set_config "CONFIG_CMDLINE+=\\" quiet\\""', 1)
if rcode:
test_run.failure("Could not set 'quiet' on kernel command line")
return
test_run.do_make_oldconfig()
# check for CMDLINE in .config file
build_dir = os.environ["KBUILD_OUTPUT"]
# read .config
cmd = 'grep CONFIG_CMDLINE %s/.config' % build_dir
(rcode, result) = commands.getstatusoutput(cmd)
if rcode:
test_run.failure("Couldn't find CMDLINE in .config file")
return
# check for quiet in CMDLINE in .config file
if not re.match(".*quiet", result):
test_run.failure("Couldn't find 'quiet' in CMDLINE in .config file")
return
# set the localversion to something unique
# then build kernel
test_run.set_localversion()
rcode = test_run.do_ttc("kbuild")
if rcode:
test_run.failure("Could not build kernel")
# install kernel
rcode = test_run.do_ttc("kinstall", 1)
if rcode:
test_run.failure("Could not install kernel")
# reboot the board
test_run.reset_target("reboot")
if test_run.check_localversion():
test_run.success("Kernel %s installed and booted on board" % test_run.kernel_id)
else:
test_run.failure("Could not verify kernel running on target board")
return
# see if option was on kernel command line from dmesg
rcode, result = test_run.run_on_target('dmesg | grep "command line:"')
if rcode:
test_run.failure("Could not verify command line on target")
return
if not re.match(".*quiet", result):
test_run.failure("Could not find 'quiet' in command line on target")
return
test_run.success("Found 'quiet' on command line on target")
def main():
# get list of valid targets
(rcode, result) = commands.getstatusoutput('ttc list -q')
tlist = result.split("\n");
if rcode:
print "Error: Problem running 'ttc list'"
sys.exit(1)
# Parse the command line
if len(sys.argv)<2:
print "Error: missing target to run test on."
usage()
print "Available targets are:"
for t in tlist:
print " %s" % t
print
sys.exit(1)
if '-h' in sys.argv:
usage()
sys.exit(1)
if '-V' in sys.argv:
print "target-test.py Ver. %d.%d.%d" % (MAJOR_VERSION, MINOR_VERSION, REVISION)
sys.exit(1)
target = sys.argv[1]
# FIXTHIS - make sure there are no conflicts - check for existing
# TTC_TARGET environment variable
if os.environ.has_key("TTC_TARGET"):
print "Error: found TTC_TARGET in environment."
print "Please do not run this test inside an existing ttc target environment."
print "Aborting test."
sys.exit(1)
test_run = ttc_test_utils.test_run_class(test_suite_name, target)
# make directory for test output
# remove leading ../ from test_data_dir, since we haven't changed
# to the kernel source dir yet
test_run.do_command("install -d %s" % test_data_dir[3:], 1)
test_run.start_log(test_data_dir[3:])
# start testing now
####################################
# TARG-001 - verify target is in list
test_run.set_id("001", "verify target is in 'ttc list'")
print "Running test %s..." % test_run.id
if target not in tlist:
test_run.failure("Error: target '%s' not found in ttc configuration" % target)
print "\n###########################################"
print "Results summary:"
test_run.show_summary_results()
sys.exit(1)
test_run.success("target '%s' is in 'ttc list'" % target)
# set up test directories
test_setup(test_run)
# run remainder of tests
test_002(test_run)
test_003(test_run)
# cwd is now the kernel source directory
test_004(test_run)
test_005(test_run)
test_006(test_run)
test_007(test_run)
test_008(test_run)
test_010(test_run)
test_011(test_run)
test_016(test_run)
test_run.close_log()
print "\n###########################################"
print "Results summary:"
test_run.show_summary_results()
if __name__=="__main__":
main()