summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/cases/storage.py
blob: 166d26b252bf9f2dbc1b69ae41a111511f755125 (plain)
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
#
# SPDX-License-Identifier: MIT
#

import re
import time

from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.data import skipIfQemu

class StorageBase(OERuntimeTestCase):
    def storage_mount(cls, tmo=1):

        (status, output) = cls.target.run('mkdir -p %s' % cls.mount_point)
        (status, output) = cls.target.run('mount %s %s' % (cls.device, cls.mount_point))
        msg = ('Mount failed: %s.' % status)
        cls.assertFalse(output, msg = msg)
        time.sleep(tmo)
        (status, output) = cls.target.run('cat /proc/mounts')
        match = re.search('%s' % cls.device, output)
        if match:
            msg = ('Device %s not mounted.' % cls.device)
            cls.assertTrue(match, msg = msg)

        (status, output) = cls.target.run('mkdir -p %s' % cls.test_dir)

        (status, output) = cls.target.run('rm -f %s/*' % cls.test_dir)
        msg = ('Failed to cleanup files @ %s/*' % cls.test_dir)
        cls.assertFalse(output, msg = msg)


    def storage_basic(cls):
        # create file on device
        (status, output) = cls.target.run('touch %s/%s' % (cls.test_dir, cls.test_file))
        msg = ('File %s not created on %s' % (cls.test_file, cls.device))
        cls.assertFalse(status, msg = msg)
        # move file
        (status, output) = cls.target.run('mv %s/%s %s/%s1' %  
                (cls.test_dir, cls.test_file, cls.test_dir, cls.test_file))
        msg = ('File %s not moved to %s' % (cls.test_file, cls.device))
        cls.assertFalse(status, msg = msg)
        # remove file
        (status, output) = cls.target.run('rm %s/%s1' % (cls.test_dir, cls.test_file))
        msg = ('File %s not removed on %s' % (cls.test_file, cls.device))
        cls.assertFalse(status, msg = msg)

    def storage_read(cls):
        # check if message is in file
        (status, output) = cls.target.run('cat  %s/%s' % 
                (cls.test_dir, cls.test_file))

        match = re.search('%s' % cls.test_msg, output)
        msg = ('Test message %s not in file %s.' % (cls.test_msg, cls.test_file))
        cls.assertEqual(status, 0,  msg = msg)

    def storage_write(cls):
        # create test message in file on device
        (status, output) = cls.target.run('echo "%s" >  %s/%s' % 
                (cls.test_msg, cls.test_dir, cls.test_file))
        msg = ('File %s not create test message on %s' % (cls.test_file, cls.device))
        cls.assertEqual(status, 0,  msg = msg)

    def storage_umount(cls, tmo=1):
        time.sleep(tmo)
        (status, output) = cls.target.run('umount %s' % cls.mount_point)

        if status == 32:
            # already unmounted, should it fail?
            return
        else:
            msg = ('Device not unmount %s' % cls.mount_point)
            cls.assertEqual(status, 0,  msg = msg)

        (status, output) = cls.target.run('cat /proc/mounts')
        match = re.search('%s' % cls.device, output)
        if match:
            msg = ('Device %s still mounted.' % cls.device)
            cls.assertTrue(match, msg = msg)


class UsbTest(StorageBase):
    '''
        This is to mimic the usb test previously done in manual bsp-hw.json
    '''
    @classmethod
    def setUpClass(self):
        self.test_msg = "Hello World - USB"
        self.mount_point = "/media/usb"
        self.device = "/dev/sda1"
        self.test_file = "usb.tst"
        self.test_dir = os.path.join(self.mount_point, "oeqa")

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['ssh.SSHTest.test_ssh'])
    def test_usb_mount(self):
        self.storage_umount(2)
        self.storage_mount(5)

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.UsbTest.test_usb_mount'])
    def test_usb_basic_operations(self):
        self.storage_basic()

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.UsbTest.test_usb_basic_operations'])
    def test_usb_basic_rw(self):
        self.storage_write()
        self.storage_read()

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.UsbTest.test_usb_mount'])
    def test_usb_umount(self):
        self.storage_umount(2)


class MMCTest(StorageBase):
    '''
        This is to mimic the usb test previously done in manual bsp-hw.json
    '''
    @classmethod
    def setUpClass(self):
        self.test_msg = "Hello World - MMC"
        self.mount_point = "/media/mmc"
        self.device = "/dev/mmcblk1p1"
        self.test_file = "mmc.tst"
        self.test_dir = os.path.join(self.mount_point, "oeqa")

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['ssh.SSHTest.test_ssh'])
    def test_mmc_mount(self):
        self.storage_umount(2)
        self.storage_mount()

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.MMCTest.test_mmc_mount'])
    def test_mmc_basic_operations(self):
        self.storage_basic()

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.MMCTest.test_mmc_basic_operations'])
    def test_mmc_basic_rw(self):
        self.storage_write()
        self.storage_read()

    @skipIfQemu('qemuall', 'Test only runs on real hardware')
    @OETestDepends(['storage.MMCTest.test_mmc_mount'])
    def test_mmc_umount(self):
        self.storage_umount(2)