Пример #1
0
 def test_one_iter_loop(self):
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0x1\\n"\n' \
               '      "MOVT R1, #0x0\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(codeblocks.loop(1), correct,
                      "One-iteration delay produces wrong code.")
Пример #2
0
 def test_non_int_iters(self):
     with self.assertRaises(TypeError):
         codeblocks.loop(3.14)
     with self.assertRaises(TypeError):
         codeblocks.loop("four")
     with self.assertRaises(TypeError):
         codeblocks.loop(triggered=False, parameter="12e-1")
Пример #3
0
 def test_max_iter(self):
     """Check that 4294967295 iterations fill the register completerly.
     """
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0xffff\\n"\n' \
               '      "MOVT R1, #0xffff\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(codeblocks.loop(4294967295), correct,
                      "Max-iter loop delay produces wrong code.")
Пример #4
0
 def test_full_top(self):
     """Check that 4294901760 iterations fill the top part of the register.
     """
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0x0\\n"\n' \
               '      "MOVT R1, #0xffff\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(codeblocks.loop(4294901760), correct,
                      "0xffff0000 loop delay produces wrong code.")
Пример #5
0
 def test_full_bottom(self):
     """Check that 65535 iterations fill the bottom part of the register.
     """
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0xffff\\n"\n' \
               '      "MOVT R1, #0x0\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(codeblocks.loop(65535), correct,
                      "Max-16-bit-iter loop delay produces wrong code.")
Пример #6
0
 def test_iters_scientific_conversion(self):
     """Test that integers in scientific notation like 1e2 are accepted.
     """
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0x64\\n"\n' \
               '      "MOVT R1, #0x0\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(
         codeblocks.loop(1e2), correct,
         "Conversion of integer-like float 1e2 to int failed.")
Пример #7
0
 def test_iters_point_zero_conversion(self):
     """Test that ints represented as floats like 4.0 are accepted.
     """
     correct = "   asm volatile (\n" \
               '      "MOVW R1, #0x4\\n"\n' \
               '      "MOVT R1, #0x0\\n"\n' \
               '      "LOOP0:\\n\\t"\n' \
               '      "NOP\\n\\t"\n' \
               '      "SUB R1, #1\\n\\t"\n' \
               '      "CMP R1, #0\\n\\t"\n' \
               '      "BNE LOOP0\\n"\n' \
               "   );"
     self.assertEqual(
         codeblocks.loop(4.0), correct,
         "Conversion of integer-like float 4.0 to int failed.")
Пример #8
0
    def __init__(self,
                 time_string=None,
                 iters=None,
                 duration=None,
                 loop_suffix="0"):
        if time_string:
            duration = read_time(time_string)
            iters = time2iters(duration)
        elif duration:
            iters = time2iters(duration)
        elif iters:
            duration = calibration * iters

        codeblock = loop(iters, loop_suffix)

        self.duration = duration
        self.iters = iters
        self.loop_suffix = loop_suffix
        self.codeblock = codeblock
Пример #9
0
 def test_zero_iters_forbidden(self):
     with self.assertRaises(ValueError):
         codeblocks.loop(0)
Пример #10
0
 def test_non_32bit_iters(self):
     with self.assertRaises(ValueError):
         codeblocks.loop(-1)
     with self.assertRaises(ValueError):
         codeblocks.loop(2**32)