示例#1
0
    def testWatchDirectory(self):
        '''Tx can watch for new files in a directory and transmit them'''

        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = [f'{TEMP_DIR}/rx_{x:05}.raw' for x in range(10)]
        tx_command = f'{TX_INSTALL} {TEMP_DIR} -q --watch-timeout 2 --filter=test_*.raw --savefile {tx_out}'
        rx_command = f'{RX} {TEMP_DIR} -q -c 1 -t 2 --prefix rx --extension raw --savefile {tx_out}'

        # Open tx to listen for new files in a directory
        proc = subprocess.Popen(tx_command.split())

        sleep(0.05)  # Give tx time to get set up

        # Create a bunch of test files in the directory, causing them to be transmitted
        test_files = [f'{TEMP_DIR}/test_{x}.raw' for x in range(10)]
        for file in test_files:
            genbytes(file, 10, FEC_SYMBOL_SIZE)

        # Wait for tx to timeout and close
        proc.wait()

        # Verify tx exited cleanly
        self.assertEqual(proc.returncode, 0)

        # Receive all the transmitted test files
        subprocess.run(rx_command.split())

        results = [
            filecmp.cmp(src, copy) for src, copy in zip(test_files, rx_out)
        ]

        self.assertEqual(all(results), True)
示例#2
0
    def testDirectoryTransmission(self):
        '''Tx can send all files currently in a directory'''

        # Create a bunch of files in a directory
        test_files = [f'{TEMP_DIR}/test_{x}.raw' for x in range(10)]
        for file in test_files:
            genbytes(file, 10, FEC_SYMBOL_SIZE)

        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = [f'{TEMP_DIR}/rx_{x:05}.raw' for x in range(10)]
        tx_command = f'{TX} {TEMP_DIR} -q --filter test_*.raw --include-all --no-listen --savefile {tx_out}'
        rx_command = f'{RX} {TEMP_DIR} -q -t 2 --prefix rx --extension raw --savefile {tx_out}'

        # Transmit all files in the directory
        subprocess.run(tx_command.split()).check_returncode()

        # Receive all the test files
        subprocess.run(rx_command.split()).check_returncode()

        # Verify all the test files match the received files
        results = [
            filecmp.cmp(src, copy) for src, copy in zip(test_files, rx_out)
        ]

        self.assertEqual(all(results), True)
示例#3
0
    def testMultiFileTransmission(self):
        '''Sending a list of files results in each file being received'''

        # Create a bunch of test files
        test_files = [f'{TEMP_DIR}/test_{x}.raw' for x in range(10)]
        for file in test_files:
            genbytes(file, 10, FEC_SYMBOL_SIZE)

        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = [f'{TEMP_DIR}/rx_{x:05}.raw' for x in range(10)]
        tx_command = f'{TX} {" ".join(test_files)} -q --savefile {tx_out}'
        rx_command = f'{RX} {TEMP_DIR} -q -c 1 -t 2 --prefix rx --extension raw --savefile {tx_out}'

        # Transmit all files the test files
        subprocess.run(tx_command.split()).check_returncode()

        # Receive all the test files
        subprocess.run(rx_command.split()).check_returncode()

        # Verify all the test files match the received files
        results = [
            filecmp.cmp(src, copy) for src, copy in zip(test_files, rx_out)
        ]

        self.assertEqual(all(results), True)
示例#4
0
    def testForwardErasureAndErrorCorrection(self):
        '''Tx and Rx can recover and correct for bit errors and packet loss'''

        test_file = f'{TEMP_DIR}/test.raw'
        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = f'{TEMP_DIR}/rx.raw'

        tx_command = f'{TX} {test_file} -q --packet-loss 0.1 --error-rate 0.004 --savefile {tx_out}'
        rx_command = f'{RX} {rx_out} -q --savefile {tx_out}'

        # Create a single test file
        genbytes(test_file, 10, FEC_SYMBOL_SIZE)  # Create test file

        # Transmit the test file
        subprocess.run(tx_command.split()).check_returncode()

        # Receive the test file
        subprocess.run(rx_command.split()).check_returncode()

        # Verify both files match
        status = filecmp.cmp(test_file, rx_out)

        self.assertEqual(status, True)
示例#5
0
    def testFECRemovesAlignmentPadding(self):
        '''Tx and Rx can recover and correct for bit errors'''

        test_file = f'{TEMP_DIR}/test.raw'
        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = f'{TEMP_DIR}/rx.raw'

        tx_command = f'{TX} {test_file} -q --packet-loss 0.1 --error-rate 0.004 --savefile {tx_out}'
        rx_command = f'{RX} {rx_out} -q -t 2 --savefile {tx_out}'

        # Create a single test file that is not aligned to FEC_SYMBOL_SIZE
        genbytes(test_file, 10, 1024)

        # Transmit the test file
        subprocess.run(tx_command.split()).check_returncode()

        # Receive the test file
        subprocess.run(rx_command.split()).check_returncode()

        # Verify both files match
        status = filecmp.cmp(test_file, rx_out)

        self.assertEqual(status, True)
示例#6
0
    def testSingleFileTransmission(self):
        '''Transmitting a single file is succesfully received and unpackaged'''

        test_file = f'{TEMP_DIR}/test.raw'
        tx_out = f'{TEMP_DIR}/tx.raw'
        rx_out = f'{TEMP_DIR}/rx.raw'

        tx_command = f'{TX} {test_file} -q --savefile {tx_out}'
        rx_command = f'{RX} {rx_out} -q -t 2 --savefile {tx_out}'

        # Create a single test file
        genbytes(test_file, 10, FEC_SYMBOL_SIZE)  # Create test file

        # Transmit the test file
        subprocess.run(tx_command.split()).check_returncode()

        # Receive the test file
        subprocess.run(rx_command.split()).check_returncode()

        # Verify both files match
        status = filecmp.cmp(test_file, rx_out)

        self.assertEqual(status, True)