def case(self):
        response = self.command("dut1", "socket new TCPSocket")
        self.socket_id = int(response.parsed['socket_id'])

        self.command("dut1", "socket " + str(self.socket_id) + " open")
        self.command("dut1", "socket " + str(self.socket_id) + " connect echo.mbedcloudtesting.com 7")

        for i in range(2):
            sentData = ""
            for size in (100, 200, 300, 120, 500):
                packet = Randomize.random_string(max_len=size, min_len=size, chars=string.ascii_uppercase)
                sentData += packet
                response = self.command("dut1", "socket " + str(self.socket_id) + " send " + str(packet))
                response.verify_trace("Socket::send() returned: " + str(size))

            received = 0
            data = ""
            totalSize = 1220
            while received < totalSize:
                response = self.command("dut1", "socket " + str(self.socket_id) + " recv " + str(totalSize))
                data += response.parsed['data'].replace(":", "")
                received += int(response.parsed['received_bytes'])

            if data != sentData:
                raise TestStepFail("Received data doesn't match the sent data")
Example #2
0
    def case(self):
        response = self.command("dut1", "socket new TCPSocket")
        self.socket_id = int(response.parsed['socket_id'])

        self.command("dut1", "socket " + str(self.socket_id) + " open")
        self.command(
            "dut1", "socket " + str(self.socket_id) +
            " connect echo.mbedcloudtesting.com 7")

        for i in range(2):
            sentData = ""
            for size in (100, 200, 300, 120, 500):
                packet = Randomize.random_string(max_len=size,
                                                 min_len=size,
                                                 chars=string.ascii_uppercase)
                sentData += packet
                response = self.command(
                    "dut1",
                    "socket " + str(self.socket_id) + " send " + str(packet))
                response.verify_trace("Socket::send() returned: " + str(size))

            received = 0
            data = ""
            totalSize = 1220
            while received < totalSize:
                response = self.command(
                    "dut1", "socket " + str(self.socket_id) + " recv " +
                    str(totalSize))
                data += response.parsed['data'].replace(":", "")
                received += int(response.parsed['received_bytes'])

            if data != sentData:
                raise TestStepFail("Received data doesn't match the sent data")
Example #3
0
    def test_random_integer_iadd(self):
        rand_integer = Randomize.random_integer(6)
        value = rand_integer.value

        rand_integer += 6
        value += 6

        self.assertEqual(rand_integer.value, value)
Example #4
0
    def test_reproduce(self):
        seed = Randomize.random_integer(20, 3).value

        def user_func(seed):
            random.seed(seed)
            return random.randint(5, 15), random.randint(15, 25)

        rep1, rep2 = user_func(seed)
        rep3, rep4 = user_func(seed)

        self.assertEqual(rep1, rep3)
        self.assertEqual(rep2, rep4)
Example #5
0
    def test_full_args(self):
        self.assertGreaterEqual(Randomize.random_integer(7, 3).value, 3)
        self.assertLessEqual(Randomize.random_integer(7, 3).value, 7)

        self.assertIn(
            Randomize.random_list_elem(['a', 'bb', 'cc']).value,
            ['a', 'bb', 'cc'])

        self.assertGreaterEqual(
            len(
                Randomize.random_string(7,
                                        3,
                                        lambda x: random.choice(x),
                                        x='e34r')), 3)
        self.assertLessEqual(
            len(
                Randomize.random_string(7,
                                        3,
                                        lambda x: random.choice(x),
                                        x='e34r')), 7)
        self.assertIn(
            Randomize.random_string(chars=["aa", "bb", "ceedee"]).value,
            ["a", "b", "c", "d", "e"])

        self.assertIn(
            Randomize.random_array_elem(['a', 'bb', 'cc']).value,
            [['a'], ['bb'], ['cc']])

        self.assertGreaterEqual(
            len(
                Randomize.random_string_array(9,
                                              3,
                                              7,
                                              2,
                                              lambda x: random.choice(x),
                                              x='e34r')), 3)
        self.assertLessEqual(
            len(
                Randomize.random_string_array(9,
                                              3,
                                              7,
                                              2,
                                              lambda x: random.choice(x),
                                              x='e34r')), 9)
Example #6
0
    def test_store_load(self):
        s_int = Randomize.random_integer(8, 4)
        s_str = Randomize.random_string(8,
                                        4,
                                        lambda x: random.choice(x),
                                        x='e34r')
        s_str_a = Randomize.random_string_array(10, 6, 7, 4)

        temp_file = tempfile.NamedTemporaryFile(delete=False)
        s_int.store(temp_file.name)
        self.assertEqual(s_int.value, s_int.load(temp_file.name).value)
        temp_file.close()

        temp_file = tempfile.NamedTemporaryFile(delete=False)
        s_str.store(temp_file.name)
        self.assertEqual(s_str.value, s_str.load(temp_file.name).value)
        temp_file.close()

        temp_file = tempfile.NamedTemporaryFile(delete=False)
        s_str_a.store(temp_file.name)
        self.assertEqual(s_str_a.value, s_str_a.load(temp_file.name).value)
        temp_file.close()
Example #7
0
 def test_random_integer_repr(self):
     rand_integer = Randomize.random_integer(6)
     self.assertEqual("%s" % rand_integer, str(rand_integer.value))
Example #8
0
 def test_random_string_array_repr(self):
     rand_str_ar = Randomize.random_string_array(5, 3)
     self.assertEqual("%s" % rand_str_ar, str(rand_str_ar.value))
Example #9
0
 def test_random_string_array_iter(self):
     for elem in Randomize.random_string_array(7, 3):
         self.assertTrue(isinstance(elem, str))
Example #10
0
 def test_random_string_array_add(self):
     rand_str = Randomize.random_string_array(5, 3)
     value = rand_str.value
     self.assertEqual(rand_str + ['world'], value + ['world'])
     self.assertEqual(['world'] + rand_str, ['world'] + value)
Example #11
0
 def test_random_string_add(self):
     rand_str = Randomize.random_string(5)
     value = rand_str.value
     self.assertEqual(rand_str + ' hello', value + ' hello')
     self.assertEqual('hello ' + rand_str, 'hello ' + value)
Example #12
0
 def test_random_integer_add(self):
     i = Randomize.random_integer(6)
     self.assertTrue(i + 6 == i.value + 6)
     self.assertTrue(6 + i == i.value + 6)
Example #13
0
 def test_random_str_lst_chars_no_str(self):  # pylint: disable=invalid-name
     with self.assertRaises(TypeError):
         Randomize.random_string(2, 1, chars=["a", "abc", 1])
Example #14
0
 def test_chars_not_list(self):
     with self.assertRaises(TypeError):
         Randomize.random_list_elem([6])
Example #15
0
 def test_chars_not_str(self):
     with self.assertRaises(ValueError):
         Randomize.random_string(7, 3, chars=6)
Example #16
0
 def test_random_string_repr(self):
     rand_str = Randomize.random_string(5)
     self.assertEqual("%s" % rand_str, str(rand_str.value))
Example #17
0
 def test_random_string_get_item(self):
     rand_str = Randomize.random_string(6)
     value = rand_str.value
     self.assertEqual(rand_str[0], value[0])
Example #18
0
 def test_random_string_str(self):
     s_str = Randomize.random_string(6)
     self.assertEqual(str(s_str), s_str.value)
Example #19
0
 def test_random_string_array_get_item(self):  # pylint: disable=invalid-name
     rand_str_ar = Randomize.random_string_array(6, 3)
     value = rand_str_ar.value
     self.assertEqual(rand_str_ar[0], value[0])