Skip to contentSkip to conversation

shared/tester: Add tester_test_abort

PATCH Applied Luiz Augusto von Dentz 3 participants 9 messages Mar 10, 2015 – Mar 11, 2015 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/4 shared/tester: Add tester_test_abort

From: Luiz Augusto von Dentz <[email protected]>

This can be used to abort tests and mark them as not run.

---
 src/shared/tester.c | 47 ++++++++++++++++++++++++++---------------------
 src/shared/tester.h |  1 +
 2 files changed, 27 insertions(+), 21 deletions(-)
src/shared/tester.c +26 -21
index ffcc2ea..acd3df7 100644
@@ -495,7 +495,7 @@ void tester_setup_failed(void)
 	test->post_teardown_func(test->test_data);
 }
 
-void tester_test_passed(void)
+static void test_result(enum test_result result)
 {
 	struct test_case *test;
 
@@ -512,33 +512,38 @@ void tester_test_passed(void)
 		test->timeout_id = 0;
 	}
 
-	test->result = TEST_RESULT_PASSED;
-	print_progress(test->name, COLOR_GREEN, "test passed");
+	test->result = result;
+	switch (result) {
+	case TEST_RESULT_PASSED:
+		print_progress(test->name, COLOR_GREEN, "test passed");
+		break;
+	case TEST_RESULT_FAILED:
+		print_progress(test->name, COLOR_RED, "test failed");
+		break;
+	case TEST_RESULT_NOT_RUN:
+		print_progress(test->name, COLOR_YELLOW, "test not run");
+		break;
+	case TEST_RESULT_TIMED_OUT:
+		print_progress(test->name, COLOR_RED, "test timed out");
+		break;
+	}
 
 	g_idle_add(teardown_callback, test);
 }
 
-void tester_test_failed(void)
+void tester_test_passed(void)
 {
-	struct test_case *test;
-
-	if (!test_current)
-		return;
-
-	test = test_current->data;
-
-	if (test->stage != TEST_STAGE_RUN)
-		return;
-
-	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
-		test->timeout_id = 0;
-	}
+	test_result(TEST_RESULT_PASSED);
+}
 
-	test->result = TEST_RESULT_FAILED;
-	print_progress(test->name, COLOR_RED, "test failed");
+void tester_test_failed(void)
+{
+	test_result(TEST_RESULT_FAILED);
+}
 
-	g_idle_add(teardown_callback, test);
+void tester_test_abort(void)
+{
+	test_result(TEST_RESULT_NOT_RUN);
 }
 
 void tester_teardown_complete(void)
src/shared/tester.h +1 -0
index 0231f19..83ef5de 100644
@@ -63,6 +63,7 @@ void tester_setup_failed(void);
 
 void tester_test_passed(void);
 void tester_test_failed(void);
+void tester_test_abort(void);
 
 void tester_teardown_complete(void);
 void tester_teardown_failed(void);
Signature · 1 line
2.1.0
author maintainer
#1 lore raw

PATCH 2/4 shared/tester: Fix teardown multiple times

From: Luiz Augusto von Dentz <[email protected]>

tester_test* can be called multiple times which cause teardown callback to be called multiple times as well leading to to crashes or strange behavior.

---
 src/shared/tester.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/shared/tester.c +9 -1
index acd3df7..d05bf08 100644
@@ -90,6 +90,7 @@ struct test_case {
 	gdouble end_time;
 	unsigned int timeout;
 	unsigned int timeout_id;
+	unsigned int teardown_id;
 	tester_destroy_func_t destroy;
 	void *user_data;
 };
@@ -113,6 +114,9 @@ static void test_destroy(gpointer data)
 	if (test->timeout_id > 0)
 		g_source_remove(test->timeout_id);
 
+	if (test->teardown_id > 0)
+		g_source_remove(test->teardown_id);
+
 	if (test->destroy)
 		test->destroy(test->user_data);
 
@@ -328,6 +332,7 @@ static gboolean teardown_callback(gpointer user_data)
 {
 	struct test_case *test = user_data;
 
+	test->teardown_id = 0;
 	test->stage = TEST_STAGE_TEARDOWN;
 
 	print_progress(test->name, COLOR_MAGENTA, "teardown");
@@ -528,7 +533,10 @@ static void test_result(enum test_result result)
 		break;
 	}
 
-	g_idle_add(teardown_callback, test);
+	if (test->teardown_id > 0)
+		return;
+
+	test->teardown_id = g_idle_add(teardown_callback, test);
 }
 
 void tester_test_passed(void)
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 3/4 shared/att: Add bt_att_has_crypto

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the possibility to check if bt_att has crypto enabled.

---
 src/shared/att.c | 8 ++++++++
 src/shared/att.h | 1 +
 2 files changed, 9 insertions(+)
src/shared/att.c +8 -0
index 7671d67..422cc2c 100644
@@ -1426,3 +1426,11 @@ bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
 
 	return sign_set_key(&att->remote_sign, sign_key, func, user_data);
 }
+
+bool bt_att_has_crypto(struct bt_att *att)
+{
+	if (!att)
+		return false;
+
+	return att->crypto ? true : false;
+}
src/shared/att.h +1 -0
index a440aaf..fb6247e 100644
@@ -90,3 +90,4 @@ bool bt_att_set_local_key(struct bt_att *att, uint8_t sign_key[16],
 			bt_att_counter_func_t func, void *user_data);
 bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
 			bt_att_counter_func_t func, void *user_data);
+bool bt_att_has_crypto(struct bt_att *att);
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 4/4 unit/test-gatt: Check if crypto is enabled

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This checks if crypto is enabled and in case it is not do not run test /TP/GAW/CL/BV-02-C.

---
 unit/test-gatt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
unit/test-gatt.c +10 -2
index 2edcacb..7668e93 100644
@@ -304,9 +304,12 @@ static gboolean context_quit(gpointer user_data)
 	if (step && step->post_func)
 		step->post_func(context);
 
-	destroy_context(context);
+	if (context->data->pdu_list[context->pdu_offset].valid)
+		tester_test_abort();
+	else
+		tester_test_passed();
 
-	tester_test_passed();
+	destroy_context(context);
 
 	return FALSE;
 }
@@ -910,6 +913,11 @@ static void test_signed_write(struct context *context)
 	uint8_t key[16] = {0xD8, 0x51, 0x59, 0x48, 0x45, 0x1F, 0xEA, 0x32, 0x0D,
 				0xC0, 0x5A, 0x2E, 0x88, 0x30, 0x81, 0x88 };
 
+	if (!bt_att_has_crypto(context->att)) {
+		context_quit(context);
+		return;
+	}
+
 	g_assert(bt_att_set_local_key(context->att, key, local_counter,
 								context));
 
Signature · 1 line
2.1.0
#4 lore raw

Re: [PATCH BlueZ 4/4] unit/test-gatt: Check if crypto is enabled

Hi Luiz,

Quoted 29 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This checks if crypto is enabled and in case it is not do not run test /TP/GAW/CL/BV-02-C.

---
 unit/test-gatt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
unit/test-gatt.c +5 -2
index 2edcacb..7668e93 100644
@@ -304,9 +304,12 @@ static gboolean context_quit(gpointer user_data)
        if (step && step->post_func)
                step->post_func(context);
 
-       destroy_context(context);
+       if (context->data->pdu_list[context->pdu_offset].valid)
+               tester_test_abort();
+       else
+               tester_test_passed();
 
-       tester_test_passed();
+       destroy_context(context);
 
        return FALSE;
 }

unit/test-gatt.c static void test_signed_write(struct context *context) · line 916

Quoted 4 lines
unit/test-gatt.c +1 -0
@@ -910,6 +913,11 @@ static void test_signed_write(struct context *context)
        uint8_t key[16] = {0xD8, 0x51, 0x59, 0x48, 0x45, 0x1F, 0xEA, 0x32, 0x0D,
                                0xC0, 0x5A, 0x2E, 0x88, 0x30, 0x81, 0x88 };
 
+       if (!bt_att_has_crypto(context->att)) {

Should we assert in this case that bt_gatt_client_write_without_response, given true for "signed_write" returns 0 without crashing? We would at least be validating the current behavior, or perhaps we should add a separate test case for it.

Quoted 10 lines
unit/test-gatt.c +4 -1
+               context_quit(context);
+               return;
+       }
+
        g_assert(bt_att_set_local_key(context->att, key, local_counter,
                                                                context));
 
--

2.1.0

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Thanks,
Arman

author maintainer
#5 lore raw

Re: [PATCH BlueZ 4/4] unit/test-gatt: Check if crypto is enabled

Hi Arman,

Quoted 34 lines · Arman Uguray

Hi Luiz,

Quoted 32 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This checks if crypto is enabled and in case it is not do not run test /TP/GAW/CL/BV-02-C.

---
 unit/test-gatt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
unit/test-gatt.c +5 -2
index 2edcacb..7668e93 100644
@@ -304,9 +304,12 @@ static gboolean context_quit(gpointer user_data)
        if (step && step->post_func)
                step->post_func(context);
 
-       destroy_context(context);
+       if (context->data->pdu_list[context->pdu_offset].valid)
+               tester_test_abort();
+       else
+               tester_test_passed();
 
-       tester_test_passed();
+       destroy_context(context);
 
        return FALSE;
 }
@@ -910,6 +913,11 @@ static void test_signed_write(struct context *context)
        uint8_t key[16] = {0xD8, 0x51, 0x59, 0x48, 0x45, 0x1F, 0xEA, 0x32, 0x0D,
                                0xC0, 0x5A, 0x2E, 0x88, 0x30, 0x81, 0x88 };
 
Quoted 7 lines

unit/test-gatt.c static void test_signed_write(struct context *context) · line 916

Quoted 1 line
unit/test-gatt.c +1 -0
+       if (!bt_att_has_crypto(context->att)) {

Should we assert in this case that bt_gatt_client_write_without_response, given true for "signed_write" returns 0 without crashing? We would at least be validating the current behavior, or perhaps we should add a separate test case for it.

What do you mean, note that this won't affect the test for seclevel which test the same code except the signature since the transport is considered secure already, all it does it check if crypto has been enabled and the make the test no run in such case since it would obviously fail. We might have to remove the use of assert in future and leave tester_run return the proper result at the end.

Quoted 18 lines
Quoted 11 lines
unit/test-gatt.c +4 -1
+               context_quit(context);
+               return;
+       }
+
        g_assert(bt_att_set_local_key(context->att, key, local_counter,
                                                                context));
 
--

2.1.0

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Thanks,
Arman

Signature · 1 line
Luiz Augusto von Dentz
maintainer
#6 lore raw

Re: [PATCH BlueZ 4/4] unit/test-gatt: Check if crypto is enabled

Hi Luiz,

Quoted 40 lines
Quoted 32 lines
Quoted 32 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This checks if crypto is enabled and in case it is not do not run test /TP/GAW/CL/BV-02-C.
---
unit/test-gatt.c | 12 ++++++++++--

1 file changed, 10 insertions(+), 2 deletions(-)
unit/test-gatt.c +5 -2
index 2edcacb..7668e93 100644
@@ -304,9 +304,12 @@ static gboolean context_quit(gpointer user_data)
       if (step && step->post_func)
               step->post_func(context);
 
-       destroy_context(context);
+       if (context->data->pdu_list[context->pdu_offset].valid)
+               tester_test_abort();
+       else
+               tester_test_passed();
 
-       tester_test_passed();
+       destroy_context(context);
 
       return FALSE;
 }
@@ -910,6 +913,11 @@ static void test_signed_write(struct context *context)
       uint8_t key[16] = {0xD8, 0x51, 0x59, 0x48, 0x45, 0x1F, 0xEA, 0x32, 0x0D,
                               0xC0, 0x5A, 0x2E, 0x88, 0x30, 0x81, 0x88 };
 
Quoted 7 lines

unit/test-gatt.c static void test_signed_write(struct context *context) · line 916

Quoted 1 line
unit/test-gatt.c +1 -0
+       if (!bt_att_has_crypto(context->att)) {

Should we assert in this case that bt_gatt_client_write_without_response, given true for "signed_write" returns 0 without crashing? We would at least be validating the current behavior, or perhaps we should add a separate test case for it.

Quoted 6 lines

What do you mean, note that this won't affect the test for seclevel which test the same code except the signature since the transport is considered secure already, all it does it check if crypto has been enabled and the make the test no run in such case since it would obviously fail. We might have to remove the use of assert in future and leave tester_run return the proper result at the end.

the tester.c code is designed to run all test cases no matter what and give you a summary. Using abort is a bad idea in these cases. If you abort, the summary is pointless. It is then either all pass or abort in the middle.

Regards

Marcel

author maintainer
#7 lore raw

Re: [PATCH BlueZ 4/4] unit/test-gatt: Check if crypto is enabled

Hi Marcel,

Quoted 42 lines · Marcel Holtmann

Hi Luiz,

Quoted 40 lines
Quoted 39 lines
Quoted 29 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This checks if crypto is enabled and in case it is not do not run test /TP/GAW/CL/BV-02-C.
---
unit/test-gatt.c | 12 ++++++++++--

1 file changed, 10 insertions(+), 2 deletions(-)
unit/test-gatt.c +5 -2
index 2edcacb..7668e93 100644
@@ -304,9 +304,12 @@ static gboolean context_quit(gpointer user_data)
       if (step && step->post_func)
               step->post_func(context);
 
-       destroy_context(context);
+       if (context->data->pdu_list[context->pdu_offset].valid)
+               tester_test_abort();
+       else
+               tester_test_passed();
 
-       tester_test_passed();
+       destroy_context(context);
 
       return FALSE;
 }

unit/test-gatt.c static void test_signed_write(struct context *context) · line 916

Quoted 4 lines
unit/test-gatt.c +1 -0
@@ -910,6 +913,11 @@ static void test_signed_write(struct context *context)
       uint8_t key[16] = {0xD8, 0x51, 0x59, 0x48, 0x45, 0x1F, 0xEA, 0x32, 0x0D,
                               0xC0, 0x5A, 0x2E, 0x88, 0x30, 0x81, 0x88 };
 
+       if (!bt_att_has_crypto(context->att)) {

Should we assert in this case that bt_gatt_client_write_without_response, given true for "signed_write" returns 0 without crashing? We would at least be validating the current behavior, or perhaps we should add a separate test case for it.

Quoted 8 lines
Quoted 6 lines

What do you mean, note that this won't affect the test for seclevel which test the same code except the signature since the transport is considered secure already, all it does it check if crypto has been enabled and the make the test no run in such case since it would obviously fail. We might have to remove the use of assert in future and leave tester_run return the proper result at the end.

the tester.c code is designed to run all test cases no matter what and give you a summary. Using abort is a bad idea in these cases. If you abort, the summary is pointless. It is then either all pass or abort in the middle.

Yep, we should proceed run all tests, but I did not bother changing this yet since I want to fix the build for platforms without crypto first.

Signature · 1 line
Luiz Augusto von Dentz
author maintainer Applied
#8 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 93 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This can be used to abort tests and mark them as not run.

---
 src/shared/tester.c | 47 ++++++++++++++++++++++++++---------------------
 src/shared/tester.h |  1 +
 2 files changed, 27 insertions(+), 21 deletions(-)
src/shared/tester.c +26 -21
index ffcc2ea..acd3df7 100644
@@ -495,7 +495,7 @@ void tester_setup_failed(void)
        test->post_teardown_func(test->test_data);
 }
 
-void tester_test_passed(void)
+static void test_result(enum test_result result)
 {
        struct test_case *test;
 
@@ -512,33 +512,38 @@ void tester_test_passed(void)
                test->timeout_id = 0;
        }
 
-       test->result = TEST_RESULT_PASSED;
-       print_progress(test->name, COLOR_GREEN, "test passed");
+       test->result = result;
+       switch (result) {
+       case TEST_RESULT_PASSED:
+               print_progress(test->name, COLOR_GREEN, "test passed");
+               break;
+       case TEST_RESULT_FAILED:
+               print_progress(test->name, COLOR_RED, "test failed");
+               break;
+       case TEST_RESULT_NOT_RUN:
+               print_progress(test->name, COLOR_YELLOW, "test not run");
+               break;
+       case TEST_RESULT_TIMED_OUT:
+               print_progress(test->name, COLOR_RED, "test timed out");
+               break;
+       }
 
        g_idle_add(teardown_callback, test);
 }
 
-void tester_test_failed(void)
+void tester_test_passed(void)
 {
-       struct test_case *test;
-
-       if (!test_current)
-               return;
-
-       test = test_current->data;
-
-       if (test->stage != TEST_STAGE_RUN)
-               return;
-
-       if (test->timeout_id > 0) {
-               g_source_remove(test->timeout_id);
-               test->timeout_id = 0;
-       }
+       test_result(TEST_RESULT_PASSED);
+}
 
-       test->result = TEST_RESULT_FAILED;
-       print_progress(test->name, COLOR_RED, "test failed");
+void tester_test_failed(void)
+{
+       test_result(TEST_RESULT_FAILED);
+}
 
-       g_idle_add(teardown_callback, test);
+void tester_test_abort(void)
+{
+       test_result(TEST_RESULT_NOT_RUN);
 }
 
 void tester_teardown_complete(void)
src/shared/tester.h +1 -1
index 0231f19..83ef5de 100644
@@ -63,6 +63,7 @@ void tester_setup_failed(void);
 
 void tester_test_passed(void);
 void tester_test_failed(void);
+void tester_test_abort(void);
 
 void tester_teardown_complete(void);
 void tester_teardown_failed(void);
--
Quoted 1 line

2.1.0

Applied.

Signature · 1 line
Luiz Augusto von Dentz