~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to scripts/floppy_test

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-17 13:54:25 UTC
  • mto: This revision was merged to the branch mainline in revision 2130.
  • Revision ID: zygmunt.krynicki@canonical.com-20130517135425-cxcenxx5t0qrtbxd
checkbox-ng: add CheckBoxNG sub-project

CheckBoxNG (or lowercase as checkbox-ng, pypi:checkbox-ng) is a clean
implementation of CheckBox on top of PlainBox. It provides a new
executable, 'checkbox' that has some of the same commands that were
previously implemented in the plainbox package.

In particular CheckBoxNG comes with the 'checkbox sru' command
(the same one as in plainbox). Later on this sub-command will be removed
from plainbox.

CheckBoxNG depends on plainbox >= 0.3

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
import os
 
4
import sys
 
5
import filecmp
 
6
import subprocess
 
7
import posixpath
 
8
 
 
9
DEFAULT_DIR = "/tmp/checkbox.floppy"
 
10
DEFAULT_DEVICE_DIR = "floppy_device"
 
11
DEFAULT_IMAGE_DIR = "floppy_image"
 
12
DEFAULT_IMAGE = "floppy.img"
 
13
 
 
14
 
 
15
class FloppyTest(object):
 
16
 
 
17
    def __init__(self, device):
 
18
        self.device = device
 
19
        self.device_dir = os.path.join(DEFAULT_DIR, DEFAULT_DEVICE_DIR)
 
20
        self.image_dir = os.path.join(DEFAULT_DIR, DEFAULT_IMAGE_DIR)
 
21
        self.image = os.path.join(DEFAULT_DIR, DEFAULT_IMAGE)
 
22
        self.interactive = True
 
23
 
 
24
        for dir in (self.device_dir, self.image_dir):
 
25
            if not posixpath.exists(dir):
 
26
                os.makedirs(dir)
 
27
 
 
28
    def run(self):
 
29
        floppyDevice = self.device
 
30
        if floppyDevice:
 
31
            print("  Testing on floppy drive %s " % floppyDevice)
 
32
        else:
 
33
            print("  Error ! No floppy drive found !")
 
34
            return 1
 
35
        # remove temp files if they exist
 
36
        os.system("umount /media/floppy 2>/dev/null")
 
37
        if (os.path.exists(self.device_dir)
 
38
            or os.path.exists(self.image_dir)
 
39
            or os.path.exists(self.image)):
 
40
            os.system("umount %s %s 2>/dev/null"
 
41
                      % (self.device_dir, self.image_dir))
 
42
            os.system("rm -rf %s %s %s 2>/dev/null"
 
43
                      % (self.device_dir, self.image_dir, self.image))
 
44
        # Create the test images
 
45
        os.mkdir(self.device_dir)
 
46
        os.mkdir(self.image_dir)
 
47
        os.system("dd if=/dev/zero of=%s bs=1k count=1440" % self.image)
 
48
        os.system("mkdosfs %s" % self.image)
 
49
        os.system("mount -o loop %s %s" % (self.image, self.image_dir))
 
50
        os.system("cp -a /etc/*.conf %s 2> /dev/null" % self.image_dir)
 
51
        os.system("umount %s" % self.image_dir)
 
52
        # start testing
 
53
        (noFloppyDisk, junkOutput1) = \
 
54
            subprocess.getstatusoutput("dd bs=1c if=%s count=0 2>/dev/null"
 
55
                                     % floppyDevice)
 
56
        if noFloppyDisk != 0:
 
57
            print("Error ! No floppy disc or bad media in %s !" % floppyDevice)
 
58
            return 1
 
59
        else:
 
60
            # writing files
 
61
            print("  Writing data to floppy disc ... ")
 
62
            (ddStatus, ddOutput) = \
 
63
                subprocess.getstatusoutput("dd if=%s of=%s bs=1k count=1440"
 
64
                                         % (self.image, floppyDevice))
 
65
            if ddStatus == 0:
 
66
                print("  Write data to floppy disc done ! ")
 
67
            else:
 
68
                print("  Error ! Write data to floppy disc error ! ")
 
69
                print("  Please check if your floppy disc is write-protected !")
 
70
                return 1
 
71
            # comparing files
 
72
            os.system("mount %s %s" % (floppyDevice, self.device_dir))
 
73
            os.system("mount -o loop %s %s" % (self.image, self.image_dir))
 
74
            print("  Comparing files ... ")
 
75
            fileList = os.listdir(self.image_dir)
 
76
            returnValue = 0
 
77
            for textFile in fileList:
 
78
                file1 = os.path.join(self.device_dir, textFile)
 
79
                file2 = os.path.join(self.image_dir, textFile)
 
80
                if filecmp.cmp(file1, file2):
 
81
                    print("        comparing file %s" % textFile)
 
82
                else:
 
83
                    print("  --  Error ! File %s comparison failed ! -- "
 
84
                          % textFile)
 
85
                    returnValue = 1
 
86
            print("  File comparison done ! ")
 
87
            # remove temp files
 
88
            os.system("umount /media/floppy 2>/dev/null")
 
89
            os.system("umount %s %s " % (self.image_dir, self.device_dir))
 
90
            os.system("rm -rf %s %s %s"
 
91
                      % (self.device_dir, self.image_dir, self.image))
 
92
            print("Done !")
 
93
            return returnValue
 
94
 
 
95
 
 
96
def main(args):
 
97
    return_values = []
 
98
    for device in args:
 
99
        test = FloppyTest(device)
 
100
        return_values.append(test.run())
 
101
 
 
102
    return 1 in return_values
 
103
 
 
104
if __name__ == "__main__":
 
105
    sys.exit(main(sys.argv[1:]))