summaryrefslogtreecommitdiff
path: root/ubuntu/scripts
diff options
context:
space:
mode:
authorBotao Sun <botao.sun@linaro.org>2014-09-02 21:59:42 +1000
committerBotao Sun <botao.sun@linaro.org>2014-09-03 21:05:40 +1000
commit23b8ef6e51da6f1c7cf6e110b657b669d8d76e76 (patch)
tree114943982451ac01d0819d5b416f121c7e2a6061 /ubuntu/scripts
parent8de5d1ee55fe34b4df375d177e3401cbc1bd534f (diff)
Add SATA Test Phase II for Linux Linaro ubuntu
Test code has been validated locally on my Host PC with a Seagate SATA drive. Signed-off by: Botao Sun <botao.sun@linaro.org> Change-Id: I872e29fe2f239f6aa61d9a113763513c5aa1983c
Diffstat (limited to 'ubuntu/scripts')
-rwxr-xr-xubuntu/scripts/sata-partition-rw.py219
1 files changed, 204 insertions, 15 deletions
diff --git a/ubuntu/scripts/sata-partition-rw.py b/ubuntu/scripts/sata-partition-rw.py
index 6642fe3..d586b79 100755
--- a/ubuntu/scripts/sata-partition-rw.py
+++ b/ubuntu/scripts/sata-partition-rw.py
@@ -20,8 +20,11 @@
#
# Author: Botao Sun <botao.sun@linaro.org>
#
+
import sys
import os
+import stat
+import time
import commands
# Switch to home path of current user to avoid any permission issue
@@ -30,7 +33,7 @@ os.chdir(home_path)
print os.getcwd()
# Save partition layout to a local file for reference
-commands.getstatusoutput("sudo fdisk -l > partition_layout.txt 2>&1")
+commands.getstatusoutput("fdisk -l > partition_layout.txt 2>&1")
device_name = sys.argv[1]
def sata_device_existence():
@@ -56,14 +59,14 @@ def sata_device_existence():
def sata_mklabel_msdos():
testcase_name = "sata_mklabel_msdos"
label_name = "msdos"
- run_command = "sudo parted -s " + device_name + " mklabel " + label_name
+ run_command = "parted -s " + device_name + " mklabel " + label_name
print run_command
mklabel_return = commands.getstatusoutput(run_command)
if mklabel_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable"
else:
- commands.getstatusoutput("sudo parted -s " + device_name + " print > partition_table_msdos.txt 2>&1")
+ commands.getstatusoutput("parted -s " + device_name + " print > partition_table_msdos.txt 2>&1")
logfile = open("partition_table_msdos.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -81,14 +84,14 @@ def sata_mklabel_msdos():
def sata_mklabel_gpt():
testcase_name = "sata_mklabel_gpt"
label_name = "gpt"
- run_command = "sudo parted -s " + device_name + " mklabel " + label_name
+ run_command = "parted -s " + device_name + " mklabel " + label_name
print run_command
mklabel_return = commands.getstatusoutput(run_command)
if mklabel_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable"
else:
- commands.getstatusoutput("sudo parted -s " + device_name + " print > partition_table_gpt.txt 2>&1")
+ commands.getstatusoutput("parted -s " + device_name + " print > partition_table_gpt.txt 2>&1")
logfile = open("partition_table_gpt.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -106,8 +109,8 @@ def sata_mklabel_gpt():
def sata_first_ext2_partition():
testcase_name = "sata_first_ext2_partition"
label_name = "msdos"
- partition_table_creation = "sudo parted -s " + device_name + " mklabel " + label_name
- first_partition_creation = "sudo parted -s " + device_name + " mkpart primary ext2 0 10%"
+ partition_table_creation = "parted -s " + device_name + " mklabel " + label_name
+ first_partition_creation = "parted -s " + device_name + " mkpart primary ext2 0 10%"
print partition_table_creation
print first_partition_creation
@@ -119,7 +122,7 @@ def sata_first_ext2_partition():
if first_partition_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable" + " Failures on " + first_partition_creation
else:
- commands.getstatusoutput("sudo fdisk -l " + device_name + " > ext2_msdos_first.txt 2>&1")
+ commands.getstatusoutput("fdisk -l " + device_name + " > ext2_msdos_first.txt 2>&1")
logfile = open("ext2_msdos_first.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -137,14 +140,14 @@ def sata_first_ext2_partition():
def sata_second_ext2_partition():
testcase_name = "sata_second_ext2_partition"
- second_partition_creation = "sudo parted -s " + device_name + " mkpart primary ext2 11% 20%"
+ second_partition_creation = "parted -s " + device_name + " mkpart primary ext2 11% 20%"
print second_partition_creation
second_partition_return = commands.getstatusoutput(second_partition_creation)
if second_partition_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable" + " Failures on " + second_partition_creation
else:
- commands.getstatusoutput("sudo fdisk -l " + device_name + " > ext2_msdos_second.txt 2>&1")
+ commands.getstatusoutput("fdisk -l " + device_name + " > ext2_msdos_second.txt 2>&1")
logfile = open("ext2_msdos_second.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -163,14 +166,14 @@ def sata_second_ext2_partition():
def sata_ext3_format():
testcase_name = "sata_ext3_format"
target_partition_name = device_name + "1"
- ext3_format = "sudo mkfs.ext3 " + target_partition_name
+ ext3_format = "mkfs.ext3 " + target_partition_name
print ext3_format
ext3_format_return = commands.getstatusoutput(ext3_format)
if ext3_format_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable" + " Failures on ext3 format command"
else:
- commands.getstatusoutput("sudo parted -s " + device_name + " print > ext3_format_first.txt 2>&1")
+ commands.getstatusoutput("parted -s " + device_name + " print > ext3_format_first.txt 2>&1")
logfile = open("ext3_format_first.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -188,14 +191,14 @@ def sata_ext3_format():
def sata_ext4_format():
testcase_name = "sata_ext4_format"
target_partition_name = device_name + "2"
- ext4_format = "sudo mkfs.ext4 " + target_partition_name
+ ext4_format = "mkfs.ext4 " + target_partition_name
print ext4_format
ext4_format_return = commands.getstatusoutput(ext4_format)
if ext4_format_return[0] != 0:
print testcase_name + ": FAIL" + " 0" + " Inapplicable" + " Failures on ext4 format command"
else:
- commands.getstatusoutput("sudo parted -s " + device_name + " print > ext4_format_second.txt 2>&1")
+ commands.getstatusoutput("parted -s " + device_name + " print > ext4_format_second.txt 2>&1")
logfile = open("ext4_format_second.txt", "r")
logcontent = logfile.readlines()
positive_counter = 0
@@ -210,6 +213,189 @@ def sata_ext4_format():
else:
print testcase_name + ": FAIL" + " 0" + " Inapplicable" + " - Could not find ext4 partition on " + device_name
+def sata_ext4_mount_umount():
+ testcase_mount = "sata_ext4_mount"
+ testcase_umount = "sata_ext4_umount"
+ target_partition_name = device_name + "2"
+ mount_point = "/media"
+ ext4_mount = "mount " + target_partition_name + " " + mount_point
+ ext4_umount = "umount " + mount_point
+
+ # umount everything from mount point - cleaning
+ umount_clean = "umount " + mount_point
+ commands.getstatusoutput(umount_clean)
+ time.sleep(5)
+ print "mount point cleaned!"
+
+ # Test mount command
+ ext4_mount_return = commands.getstatusoutput(ext4_mount)
+ time.sleep(5)
+ if ext4_mount_return[0] != 0:
+ print testcase_mount + ": FAIL" + " 0" + " Inapplicable" + " Failures on ext4 partition mount!"
+ else:
+ commands.getstatusoutput("mount > mount_log.txt 2>&1")
+ logfile = open("mount_log.txt", "r")
+ logcontent = logfile.readlines()
+ positive_counter = 0
+ for i in range(0, len(logcontent)):
+ if target_partition_name in logcontent[i]:
+ positive_counter = positive_counter + 1
+ logfile.close()
+ if positive_counter > 0:
+ print testcase_mount + ": PASS" + " 0" + " Inapplicable"
+ else:
+ print testcase_mount + ": FAIL" + " 0" + " Inapplicable" + " - Could not find ext4 partition in mount log!"
+
+ # Test umount command
+ ext4_umount_return = commands.getstatusoutput(ext4_umount)
+ time.sleep(5)
+ if ext4_umount_return[0] != 0:
+ print testcase_umount + ": FAIL" + " 0" + " Inapplicable" + " Failures on ext4 partition umount!"
+ else:
+ commands.getstatusoutput("mount > umount_log.txt 2>&1")
+ logfile = open("umount_log.txt", "r")
+ logcontent = logfile.readlines()
+ positive_counter = 0
+ for i in range(0, len(logcontent)):
+ if target_partition_name in logcontent[i]:
+ positive_counter = positive_counter + 1
+ logfile.close()
+ if positive_counter > 0:
+ print testcase_umount + ": FAIL" + " 0" + " Inapplicable" + " - ext4 partition umount failed from " + mount_point
+ else:
+ print testcase_umount + ": PASS" + " 0" + " Inapplicable"
+
+def sata_ext4_file_fill_edit():
+ testcase_filefill = "sata_ext4_file_fill"
+ testcase_fileedit = "sata_ext4_file_edit"
+ target_partition_name = device_name + "2"
+ mount_point = "/media"
+ ext4_mount = "mount " + target_partition_name + " " + mount_point
+ ext4_umount = "umount " + mount_point
+
+ # umount everything from mount point - cleaning
+ umount_clean = "umount " + mount_point
+ commands.getstatusoutput(umount_clean)
+ time.sleep(5)
+ print "mount point cleaned!"
+ commands.getstatusoutput(ext4_mount)
+ time.sleep(5)
+
+ # Create a 1MB file with 0x00 filled in
+ file_creation_1M = "dd if=/dev/zero of=/media/file_1MB bs=4k count=256"
+ file_creation_1M_return = commands.getstatusoutput(file_creation_1M)
+ if file_creation_1M_return[0] != 0:
+ print testcase_filefill + ": FAIL" + " 0" + " Inapplicable" + " failed to create a 1MB file filled with 0x00!"
+ elif os.path.isfile("/media/file_1MB") == False:
+ print testcase_filefill + ": FAIL" + " 0" + " Inapplicable" + " file_1MB can not be found!"
+ elif os.path.getsize("/media/file_1MB") != 1048576:
+ print testcase_filefill + ": FAIL" + " 0" + " Inapplicable" + " file_1MB size incorrect!"
+ else:
+ print testcase_filefill + ": PASS" + " 0" + " Inapplicable"
+
+ # Create an empty file then write something into it
+ testfile_name = "/media/test_file.txt"
+ if os.path.isfile(testfile_name) == True:
+ os.unlink(testfile_name)
+ file_creation_empty = "touch " + testfile_name
+ file_creation_empty_return = commands.getstatusoutput(file_creation_empty)
+ if file_creation_empty_return[0] != 0:
+ print testcase_fileedit + ": FAIL" + " 0" + " Inapplicable" + " failed to create an empty file!"
+ elif os.path.isfile(testfile_name) == False:
+ print testcase_fileedit + ": FAIL" + " 0" + " Inapplicable" + " " + testfile_name + " can not be found!"
+ else:
+ os.chmod(testfile_name, stat.S_IRWXU)
+ test_string = "This is a test file"
+ testfile = open(testfile_name, "a")
+ testfile.write(test_string)
+ testfile.close()
+ # Validating
+ testfile = open(testfile_name, "r")
+ return_string = testfile.read()
+ if return_string != test_string:
+ print testcase_fileedit + ": FAIL" + " 0" + " Inapplicable" + " file content doesn't match!"
+ else:
+ print testcase_fileedit + ": PASS" + " 0" + " Inapplicable"
+ testfile.close()
+
+ # umount everything from mount point - cleaning
+ umount_clean = "umount " + mount_point
+ commands.getstatusoutput(umount_clean)
+ time.sleep(5)
+ print "mount point cleaned!"
+
+def sata_ext4_dd_write_read():
+ testcase_dd_write = "sata_ext4_dd_write"
+ testcase_dd_read = "sata_ext4_dd_read"
+ target_partition_name = device_name + "2"
+ mount_point = "/media"
+ ext4_mount = "mount " + target_partition_name + " " + mount_point
+ ext4_umount = "umount " + mount_point
+
+ # umount everything from mount point - cleaning
+ umount_clean = "umount " + mount_point
+ commands.getstatusoutput(umount_clean)
+ time.sleep(5)
+ print "mount point cleaned!"
+ commands.getstatusoutput(ext4_mount)
+ time.sleep(5)
+
+ # Test write speed by using dd, direct write
+ dd_write_1G = "dd if=/dev/zero of=/media/file_1GB oflag=direct bs=4k count=262144 > dd_write_1GB_stdout.txt 2>&1"
+ dd_write_1G_return = commands.getstatusoutput(dd_write_1G)
+ if dd_write_1G_return[0] != 0:
+ print testcase_dd_write + ": FAIL" + " 0" + " Inapplicable" + " failed to create a 1GB file using dd!"
+ elif os.path.isfile("/media/file_1GB") == False:
+ print testcase_dd_write + ": FAIL" + " 0" + " Inapplicable" + " file_1GB can not be found!"
+ elif os.path.getsize("/media/file_1GB") != 1073741824:
+ print testcase_dd_write + ": FAIL" + " 0" + " Inapplicable" + " file_1GB size incorrect!"
+ else:
+ target_list = []
+ writelog = open("dd_write_1GB_stdout.txt", "r")
+ writelog_content = writelog.readlines()
+ for item in writelog_content:
+ if str(1073741824) in item:
+ target_list = item.split(",")[-1].strip("\n").split(" ")
+ break
+ if target_list == []:
+ print testcase_dd_write + ": FAIL" + " 0" + " Inapplicable" + " can not find write performance result."
+ elif len(target_list) < 2:
+ print testcase_dd_write + ": FAIL" + " 0" + " Inapplicable" + " write test result parsing failed, please check the log output!"
+ else:
+ print testcase_dd_write + ": PASS" + " " + str(target_list[-2]) + " " + target_list[-1]
+ writelog.close()
+
+ # Test read speed by using dd, direct read
+ if os.path.isfile("/media/file_1GB") == False:
+ print testcase_dd_read + ": FAIL" + " 0" + " Inapplicable" + " can not find the target file to read."
+ else:
+ dd_read_1G = "dd if=/media/file_1GB iflag=direct of=/dev/null bs=4k count=262144 > dd_read_1GB_stdout.txt 2>&1"
+ dd_read_1G_return = commands.getstatusoutput(dd_read_1G)
+ if dd_read_1G_return[0] != 0:
+ print testcase_dd_read + ": FAIL" + " 0" + " Inapplicable" + " failed to read the target file!"
+ else:
+ target_list = []
+ readlog = open("dd_read_1GB_stdout.txt", "r")
+ readlog_content = readlog.readlines()
+ for item in readlog_content:
+ if str(1073741824) in item:
+ target_list = item.split(",")[-1].strip("\n").split(" ")
+ break
+ if target_list == []:
+ print testcase_dd_read + ": FAIL" + " 0" + " Inapplicable" + " can not find read performance result."
+ elif len(target_list) < 2:
+ print testcase_dd_read + ": FAIL" + " 0" + " Inapplicable" + " read test result parsing failed, please check the log output!"
+ else:
+ print testcase_dd_read + ": PASS" + " " + str(target_list[-2]) + " " + target_list[-1]
+ readlog.close()
+
+ # umount and clean
+ os.unlink("/media/file_1GB")
+ umount_clean = "umount " + mount_point
+ commands.getstatusoutput(umount_clean)
+ time.sleep(5)
+ print "mount point cleaned!"
+
# Run all test
sata_device_existence()
sata_mklabel_msdos()
@@ -217,4 +403,7 @@ sata_mklabel_gpt()
sata_first_ext2_partition()
sata_second_ext2_partition()
sata_ext3_format()
-sata_ext4_format() \ No newline at end of file
+sata_ext4_format()
+sata_ext4_mount_umount()
+sata_ext4_file_fill_edit()
+sata_ext4_dd_write_read()