def test_number_of_reults(self): """ This test checks the number of results to match a previous calculated value. """ instance_count = 7 restarts = 13 expected_number_of_result = instance_count * restarts log_name = 'test_log' sim_learn.main([ "sim_learn", "8", "2", "id", "xor", "10", str(restarts), str(instance_count), "1234", "1234", log_name ]) def line_count(file_object): """ :param file_object: :return: number of lines """ count = 0 while file_object.readline() != '': count = count + 1 return count # Check if the number of results is correct log_file = open(log_name + '.log', 'r') self.assertEqual(line_count(log_file), expected_number_of_result, 'Unexpected number of results') log_file.close()
def test_ip_mod2_lightweight_secure(self): """This tests the lightweight secure transformation and inner product mod 2 combiner.""" sim_learn.main([ "8", "2", "lightweight_secure", "ip_mod2", "20", "1", "2", "1234", "1234", self.log_parameter("test_ip_mod2_lightweight_secure") ])
def test_log_name(self): """This tests for the expected number of lines in the main log file.""" instance_count = 2 log_name = "test_log_name" sim_learn.main([ "8", "2", "id", "xor", "10", "1", str(instance_count), "1234", "1234", self.log_parameter(log_name) ]) def line_count(file_object): """ :param file_object: :return: number of lines """ count = 0 while file_object.readline() != '': count = count + 1 return count # Check if the number of results is correct log_file = open('logs/' + LOG_PATH + log_name + '.log', 'r') self.assertEqual(line_count(log_file), instance_count, 'Unexpected number of results') log_file.close()
def test_lightweight_secure(self): """This tests the lightweight secure transformation and xor combiner.""" sim_learn.main([ "8", "2", "lightweight_secure", "xor", "20", "1", "2", "1234", "1234", self.log_parameter("test_lightweight_secure") ])
def check_seeds(self, parameter_set1, parameter_set2, log_path): """ This method checks the results of sim_learn for different parameter lists. :param parameter_set1: list of string :param parameter_set2: list of string :param log_path: string """ sim_learn.main(parameter_set1) res_param_set1 = self.read_log('logs/' + log_path) sim_learn.main(parameter_set2) res_param_set2 = self.read_log('logs/' + log_path) # Test challenge seed impact # remove pid del res_param_set1[0][0] del res_param_set2[0][0] # remove timing info del res_param_set1[0][2] del res_param_set2[0][2] # remove memory info del res_param_set1[0][-1] del res_param_set2[0][-1] self.assertNotEqual(res_param_set1, res_param_set2) sim_learn.main(parameter_set1) res_param_set1_2 = self.read_log('logs/' + log_path) sim_learn.main(parameter_set2) res_param_set2_2 = self.read_log('logs/' + log_path) # Test challenge to be deterministic # remove pid del res_param_set1_2[0][0] del res_param_set2_2[0][0] # remove timing info del res_param_set1_2[0][2] del res_param_set2_2[0][2] # remove memory usage del res_param_set1_2[0][-1] del res_param_set2_2[0][-1] self.assertEqual(res_param_set2, res_param_set2_2) self.assertEqual(res_param_set1, res_param_set1_2)
def test_ip_mod2_1_n_bent(self): """This tests the one to n bent transformation and inner product mod 2 combiner.""" sim_learn.main([ "sim_learn", "8", "2", "1_n_bent", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_ip_mod2_mm(self): """This tests the mm transformation and inner product mod 2 combiner.""" sim_learn.main([ "sim_learn", "8", "2", "mm", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_ip_mod2_1_1_bent(self): sim_learn.main([ "sim_learn", "8", "2", "1_1_bent", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_ip_mod2_mm(self): sim_learn.main([ "sim_learn", "8", "2", "mm", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_id(self): sim_learn.main([ "sim_learn", "8", "2", "id", "xor", "20", "1", "2", "1234", "1234" ])
def test_lightweight_secure_original(self): sim_learn.main([ "sim_learn", "8", "2", "lightweight_secure_original", "xor", "20", "1", "2", "1234", "1234" ])
def test_permutation_atf(self): """This tests the atf permutation transformation and xor combiner.""" sim_learn.main(["8", "2", "permutation_atf", "xor", "10", "1", "2", "1234", "1234", self.log_parameter("test_permutation_atf")])
def test_ip_mod2_atf(self): """This tests the atf transformation and inner product mod 2 combiner.""" sim_learn.main( ["8", "2", "atf", "ip_mod2", "20", "1", "2", "1234", "1234", self.log_parameter("test_ip_mod2_atf")])
def test_id(self): """This tests the id transformation and xor combiner.""" sim_learn.main(["8", "2", "id", "xor", "20", "1", "2", "1234", "1234", self.log_parameter("test_id")])
def test_atf(self): sim_learn.main([ "sim_learn", "8", "2", "atf", "xor", "20", "1", "2", "1234", "1234" ])
def test_mm(self): sim_learn.main([ "sim_learn", "8", "2", "mm", "xor", "20", "1", "2", "1234", "1234" ])
def test_atf(self): """This tests the atf transformation and xor combiner.""" sim_learn.main([ "sim_learn", "8", "2", "atf", "xor", "20", "1", "2", "1234", "1234" ])
def test_1_1_bent(self): sim_learn.main([ "sim_learn", "8", "2", "1_1_bent", "xor", "20", "1", "2", "1234", "1234" ])
def test_mm(self): """This tests the mm transformation and xor combiner.""" sim_learn.main([ "sim_learn", "8", "2", "mm", "xor", "20", "1", "2", "1234", "1234" ])
def test_ip_mod2_atf(self): sim_learn.main([ "sim_learn", "8", "2", "atf", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_lightweight_secure_original(self): """This tests the lightweight secure original transformation and xor combiner.""" sim_learn.main([ "sim_learn", "8", "2", "lightweight_secure_original", "xor", "20", "1", "2", "1234", "1234" ])
def test_ip_mod2_lightweight_secure(self): sim_learn.main([ "sim_learn", "8", "2", "lightweight_secure", "ip_mod2", "20", "1", "2", "1234", "1234" ])
def test_1_1_bent(self): """This tests the one to one bent transformation and xor combiner.""" sim_learn.main([ "sim_learn", "8", "2", "1_1_bent", "xor", "20", "1", "2", "1234", "1234" ])
def test_permutation_atf(self): sim_learn.main([ "sim_learn", "8", "2", "permutation_atf", "xor", "10", "1", "2", "1234", "1234" ])
def test_ip_mod2_id(self): """This tests the identity transformation and inner product mod 2 combiner.""" sim_learn.main([ "sim_learn", "8", "2", "id", "ip_mod2", "20", "1", "2", "1234", "1234" ])