[Spice-devel] [PATCH libcacard v2 30/35] tests: Consolidate the tests for hw and non-hw versions

Jakub Jelen jjelen at redhat.com
Thu Aug 2 09:44:02 UTC 2018


Signed-off-by: Jakub Jelen <jjelen at redhat.com>
Reviewed-by: Robert Relyea <rrelyea at redhat.com>
---
 tests/common.c    | 20 ++++++++++++++++++++
 tests/hwtests.c   | 44 +++++---------------------------------------
 tests/libcacard.c |  3 +--
 3 files changed, 26 insertions(+), 41 deletions(-)

diff --git a/tests/common.c b/tests/common.c
index 713dd8f..d222c6e 100644
--- a/tests/common.c
+++ b/tests/common.c
@@ -583,6 +583,12 @@ void test_empty_applets(void)
 
     VReader *reader = vreader_get_reader_by_id(0);
 
+    /* Skip the HW tests without physical card */
+    if (isHWTests() && vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
+        g_test_skip("No physical card found");
+        return;
+    }
 
     /* select the empty applet A00000007902FB, which should be empty buffer */
     select_aid(reader, applet_02fb, sizeof(applet_02fb));
@@ -673,6 +679,13 @@ void test_get_response(void)
         0x00, 0x52, 0x00, 0x00, 0x02, 0x01, 0x02 /* no L_e */
     };
 
+    /* Skip the HW tests without physical card */
+    if (isHWTests() && vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
+        g_test_skip("No physical card found");
+        return;
+    }
+
     /* select CCC */
     select_applet(reader, TEST_CCC);
 
@@ -757,6 +770,13 @@ void check_login_count(void)
     };
     g_assert_nonnull(reader);
 
+    /* Skip the HW tests without physical card */
+    if (isHWTests() && vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
+        g_test_skip("No physical card found");
+        return;
+    }
+
     /* Get login count */
     status = vreader_xfr_bytes(reader,
                                login, sizeof(login),
diff --git a/tests/hwtests.c b/tests/hwtests.c
index e357ea2..4d6a61d 100644
--- a/tests/hwtests.c
+++ b/tests/hwtests.c
@@ -106,14 +106,14 @@ static void test_list(void)
         }
         vreader_free(r);
     }
+    vreader_list_delete(list);
+
     if (cards == 0) {
-        vreader_list_delete(list);
         g_test_skip("No physical card found");
         return;
     }
 
     g_assert_cmpint(cards, ==, 1);
-    vreader_list_delete(list);
 }
 
 static void do_login(VReader *reader)
@@ -247,40 +247,6 @@ static void test_sign(void)
     vreader_free(reader); /* get by id ref */
 }
 
-static void test_empty_applets_hw(void) {
-
-    VReader *reader = vreader_get_reader_by_id(0);
-
-    /* Skip the HW tests without physical card */
-    if (vreader_card_is_present(reader) != VREADER_OK) {
-        vreader_free(reader);
-        g_test_skip("No physical card found");
-        return;
-    }
-
-    vreader_free(reader); /* get by id ref */
-
-    /* run the actual test */
-    test_empty_applets();
-}
-
-static void test_get_response_hw(void) {
-
-    VReader *reader = vreader_get_reader_by_id(0);
-
-    /* Skip the HW tests without physical card */
-    if (vreader_card_is_present(reader) != VREADER_OK) {
-        vreader_free(reader);
-        g_test_skip("No physical card found");
-        return;
-    }
-
-    vreader_free(reader); /* get by id ref */
-
-    /* run the actual test */
-    test_get_response();
-}
-
 /* Try to pass bad formatted PKCS#1.5 data and make sure the libcacard does not
  * crash while handling them
  */
@@ -387,12 +353,12 @@ int main(int argc, char *argv[])
 
     g_test_add_func("/hw-tests/list", test_list);
     g_test_add_func("/hw-tests/passthrough-applet", test_passthrough_applets);
-    g_test_add_func("/hw-tests/login", test_login);
     g_test_add_func("/hw-tests/check-login-count", check_login_count);
+    g_test_add_func("/hw-tests/login", test_login);
     g_test_add_func("/hw-tests/sign", test_sign);
     g_test_add_func("/hw-tests/sign-bad-data", test_sign_bad_data_x509);
-    g_test_add_func("/hw-tests/empty-applets", test_empty_applets_hw);
-    g_test_add_func("/hw-tests/get-response", test_get_response_hw);
+    g_test_add_func("/hw-tests/empty-applets", test_empty_applets);
+    g_test_add_func("/hw-tests/get-response", test_get_response);
 
     ret = g_test_run();
 
diff --git a/tests/libcacard.c b/tests/libcacard.c
index 0c3b178..6bb3be7 100644
--- a/tests/libcacard.c
+++ b/tests/libcacard.c
@@ -559,8 +559,7 @@ static void test_remove(void)
 
     status = vreader_remove_reader(reader);
     g_assert_cmpint(status, ==, VREADER_OK);
-    vreader_free(reader); /* get by id ref */
-    //vreader_free(reader);
+    vreader_free(reader);
 
     reader = vreader_get_reader_by_id(0);
     g_assert_null(reader);
-- 
2.17.1



More information about the Spice-devel mailing list