2015-05-19 15:00:59

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 0/5] Use tester framework for unit-tests

Used the tester framework for unit-tests
to produce much better results.

Gowtham Anandha Babu (5):
unit/test-ringbuf: Use tester framework
unit/test-textfile: Use tester framework
unit/test-queue: Use tester framework
unit/test-lib: Use tester framework
unit/test-uuid: Use tester framework

Makefile.am | 8 ++--
unit/test-lib.c | 106 +++++++++++++++++++++++++++++----------------------
unit/test-queue.c | 55 ++++++++++++++++----------
unit/test-ringbuf.c | 31 ++++++++-------
unit/test-textfile.c | 49 +++++++++++-------------
unit/test-uuid.c | 52 ++++++++++++++-----------
6 files changed, 170 insertions(+), 131 deletions(-)

--
1.9.1



2015-05-22 11:19:38

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 0/5] Use tester framework for unit-tests

Hi Gowtham,

On Fri, May 22, 2015 at 1:20 PM, Gowtham Anandha Babu
<[email protected]> wrote:
> Ping.
>
>> -----Original Message-----
>> From: [email protected] [mailto:linux-bluetooth-
>> [email protected]] On Behalf Of Gowtham Anandha Babu
>> Sent: Tuesday, May 19, 2015 8:31 PM
>> To: [email protected]
>> Cc: [email protected]; [email protected]; Gowtham Anandha
>> Babu
>> Subject: [PATCH 0/5] Use tester framework for unit-tests
>>
>> Used the tester framework for unit-tests to produce much better results.
>>
>> Gowtham Anandha Babu (5):
>> unit/test-ringbuf: Use tester framework
>> unit/test-textfile: Use tester framework
>> unit/test-queue: Use tester framework
>> unit/test-lib: Use tester framework
>> unit/test-uuid: Use tester framework
>>
>> Makefile.am | 8 ++--
>> unit/test-lib.c | 106
> +++++++++++++++++++++++++++++--------------------
>> --
>> unit/test-queue.c | 55 ++++++++++++++++----------
>> unit/test-ringbuf.c | 31 ++++++++------- unit/test-textfile.c | 49
>> +++++++++++-------------
>> unit/test-uuid.c | 52 ++++++++++++++-----------
>> 6 files changed, 170 insertions(+), 131 deletions(-)
>>
>> --
>> 1.9.1
>>
>> --
>> 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

Applied, thanks.



--
Luiz Augusto von Dentz

2015-05-22 10:20:41

by Gowtham Anandha Babu

[permalink] [raw]
Subject: RE: [PATCH 0/5] Use tester framework for unit-tests

Ping.

> -----Original Message-----
> From: [email protected] [mailto:linux-bluetooth-
> [email protected]] On Behalf Of Gowtham Anandha Babu
> Sent: Tuesday, May 19, 2015 8:31 PM
> To: [email protected]
> Cc: [email protected]; [email protected]; Gowtham Anandha
> Babu
> Subject: [PATCH 0/5] Use tester framework for unit-tests
>
> Used the tester framework for unit-tests to produce much better results.
>
> Gowtham Anandha Babu (5):
> unit/test-ringbuf: Use tester framework
> unit/test-textfile: Use tester framework
> unit/test-queue: Use tester framework
> unit/test-lib: Use tester framework
> unit/test-uuid: Use tester framework
>
> Makefile.am | 8 ++--
> unit/test-lib.c | 106
+++++++++++++++++++++++++++++--------------------
> --
> unit/test-queue.c | 55 ++++++++++++++++----------
> unit/test-ringbuf.c | 31 ++++++++------- unit/test-textfile.c | 49
> +++++++++++-------------
> unit/test-uuid.c | 52 ++++++++++++++-----------
> 6 files changed, 170 insertions(+), 131 deletions(-)
>
> --
> 1.9.1
>
> --
> 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


2015-05-19 15:01:03

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 4/5] unit/test-lib: Use tester framework

---
Makefile.am | 3 +-
unit/test-lib.c | 106 ++++++++++++++++++++++++++++++++------------------------
2 files changed, 63 insertions(+), 46 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 6aa8410..f14539d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -382,7 +382,8 @@ unit_test_gobex_apparam_LDADD = @GLIB_LIBS@
unit_tests += unit/test-lib

unit_test_lib_SOURCES = unit/test-lib.c
-unit_test_lib_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+unit_test_lib_LDADD = src/libshared-glib.la \
+ lib/libbluetooth-internal.la @GLIB_LIBS@

unit_tests += unit/test-gatt

diff --git a/unit/test-lib.c b/unit/test-lib.c
index ef0cffc..bd4c5ee 100644
--- a/unit/test-lib.c
+++ b/unit/test-lib.c
@@ -31,27 +31,30 @@
#include <errno.h>

#include "src/shared/util.h"
+#include "src/shared/tester.h"

#include "lib/sdp.h"
#include "lib/sdp_lib.h"

-static void test_ntoh64(void)
+static void test_ntoh64(const void *data)
{
uint64_t test = 0x123456789abcdef;

g_assert(ntoh64(test) == be64toh(test));
g_assert(ntoh64(test) == be64_to_cpu(test));
+ tester_test_passed();
}

-static void test_hton64(void)
+static void test_hton64(const void *data)
{
uint64_t test = 0x123456789abcdef;

g_assert(hton64(test) == htobe64(test));
g_assert(hton64(test) == cpu_to_be64(test));
+ tester_test_passed();
}

-static void test_sdp_get_access_protos_valid(void)
+static void test_sdp_get_access_protos_valid(const void *data)
{
sdp_record_t *rec;
sdp_list_t *aproto, *apseq, *proto[2];
@@ -91,9 +94,10 @@ static void test_sdp_get_access_protos_valid(void)
sdp_list_free(aproto, NULL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_access_protos_nodata(void)
+static void test_sdp_get_access_protos_nodata(const void *data)
{
sdp_record_t *rec;
sdp_list_t *aproto;
@@ -108,9 +112,10 @@ static void test_sdp_get_access_protos_nodata(void)
g_assert(err == -1 && errno == ENODATA);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_access_protos_invalid_dtd1(void)
+static void test_sdp_get_access_protos_invalid_dtd1(const void *tdata)
{
const uint32_t u32 = 0xdeadbeeb;
sdp_record_t *rec;
@@ -135,9 +140,10 @@ static void test_sdp_get_access_protos_invalid_dtd1(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_access_protos_invalid_dtd2(void)
+static void test_sdp_get_access_protos_invalid_dtd2(const void *tdata)
{
uint8_t dtd = SDP_UINT8, u8 = 0xff;
void *dtds = &dtd, *values = &u8;
@@ -163,9 +169,10 @@ static void test_sdp_get_access_protos_invalid_dtd2(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_lang_attr_valid(void)
+static void test_sdp_get_lang_attr_valid(const void *data)
{
sdp_record_t *rec;
sdp_list_t *list;
@@ -179,9 +186,10 @@ static void test_sdp_get_lang_attr_valid(void)

sdp_list_free(list, free);
sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_lang_attr_nodata(void)
+static void test_sdp_get_lang_attr_nodata(const void *data)
{
sdp_record_t *rec;
sdp_list_t *list;
@@ -193,9 +201,10 @@ static void test_sdp_get_lang_attr_nodata(void)
g_assert(err == -1 && errno == ENODATA);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_lang_attr_invalid_dtd(void)
+static void test_sdp_get_lang_attr_invalid_dtd(const void *tdata)
{
uint8_t dtd1 = SDP_UINT16, dtd2 = SDP_UINT32;
uint32_t u32 = 0xdeadbeeb;
@@ -243,9 +252,10 @@ static void test_sdp_get_lang_attr_invalid_dtd(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_profile_descs_valid(void)
+static void test_sdp_get_profile_descs_valid(const void *data)
{
sdp_profile_desc_t profile;
sdp_record_t *rec;
@@ -267,9 +277,10 @@ static void test_sdp_get_profile_descs_valid(void)
g_assert(err == 0 && list != NULL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_profile_descs_nodata(void)
+static void test_sdp_get_profile_descs_nodata(const void *data)
{
sdp_record_t *rec;
sdp_list_t *list;
@@ -281,9 +292,10 @@ static void test_sdp_get_profile_descs_nodata(void)
g_assert(err == -1 && errno == ENODATA);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_profile_descs_invalid_dtd(void)
+static void test_sdp_get_profile_descs_invalid_dtd(const void *tdata)
{
uint8_t dtd1 = SDP_UUID16, dtd2 = SDP_UINT32;
uint32_t u32 = 0xdeadbeeb;
@@ -354,9 +366,10 @@ static void test_sdp_get_profile_descs_invalid_dtd(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_profile_descs_workaround(void)
+static void test_sdp_get_profile_descs_workaround(const void *tdata)
{
uint8_t dtd1 = SDP_UUID16, dtd2 = SDP_UINT16, dtd3 = SDP_UINT32;
uint16_t u16 = 0x1234;
@@ -404,9 +417,10 @@ static void test_sdp_get_profile_descs_workaround(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

-static void test_sdp_get_server_ver(void)
+static void test_sdp_get_server_ver(const void *tdata)
{
uint16_t u16 = 0x1234;
uint32_t u32 = 0xdeadbeeb;
@@ -451,42 +465,44 @@ static void test_sdp_get_server_ver(void)
g_assert(err == -1 && errno == EINVAL);

sdp_record_free(rec);
+ tester_test_passed();
}

int main(int argc, char *argv[])
{
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/lib/ntoh64", test_ntoh64);
- g_test_add_func("/lib/hton64", test_hton64);
-
- g_test_add_func("/lib/sdp_get_access_protos/valid",
- test_sdp_get_access_protos_valid);
- g_test_add_func("/lib/sdp_get_access_protos/nodata",
- test_sdp_get_access_protos_nodata);
- g_test_add_func("/lib/sdp_get_access_protos/invalid_dtd1",
- test_sdp_get_access_protos_invalid_dtd1);
- g_test_add_func("/lib/sdp_get_access_protos/invalid_dtd2",
- test_sdp_get_access_protos_invalid_dtd2);
-
- g_test_add_func("/lib/sdp_get_lang_attr/valid",
- test_sdp_get_lang_attr_valid);
- g_test_add_func("/lib/sdp_get_lang_attr/nodata",
- test_sdp_get_lang_attr_nodata);
- g_test_add_func("/lib/sdp_get_lang_attr/invalid_dtd",
- test_sdp_get_lang_attr_invalid_dtd);
-
- g_test_add_func("/lib/sdp_get_profile_descs/valid",
- test_sdp_get_profile_descs_valid);
- g_test_add_func("/lib/sdp_get_profile_descs/nodata",
- test_sdp_get_profile_descs_nodata);
- g_test_add_func("/lib/sdp_get_profile_descs/invalid_dtd",
- test_sdp_get_profile_descs_invalid_dtd);
+ tester_init(&argc, &argv);
+
+ tester_add("/lib/ntoh64", NULL, NULL, test_ntoh64, NULL);
+ tester_add("/lib/hton64", NULL, NULL, test_hton64, NULL);
+
+ tester_add("/lib/sdp_get_access_protos/valid", NULL, NULL,
+ test_sdp_get_access_protos_valid, NULL);
+ tester_add("/lib/sdp_get_access_protos/nodata", NULL, NULL,
+ test_sdp_get_access_protos_nodata, NULL);
+ tester_add("/lib/sdp_get_access_protos/invalid_dtd1", NULL, NULL,
+ test_sdp_get_access_protos_invalid_dtd1, NULL);
+ tester_add("/lib/sdp_get_access_protos/invalid_dtd2", NULL, NULL,
+ test_sdp_get_access_protos_invalid_dtd2, NULL);
+
+ tester_add("/lib/sdp_get_lang_attr/valid", NULL, NULL,
+ test_sdp_get_lang_attr_valid, NULL);
+ tester_add("/lib/sdp_get_lang_attr/nodata", NULL, NULL,
+ test_sdp_get_lang_attr_nodata, NULL);
+ tester_add("/lib/sdp_get_lang_attr/invalid_dtd", NULL, NULL,
+ test_sdp_get_lang_attr_invalid_dtd, NULL);
+
+ tester_add("/lib/sdp_get_profile_descs/valid", NULL, NULL,
+ test_sdp_get_profile_descs_valid, NULL);
+ tester_add("/lib/sdp_get_profile_descs/nodata", NULL, NULL,
+ test_sdp_get_profile_descs_nodata, NULL);
+ tester_add("/lib/sdp_get_profile_descs/invalid_dtd", NULL, NULL,
+ test_sdp_get_profile_descs_invalid_dtd, NULL);
/* Test for workaround commented on sdp_get_profile_descs() */
- g_test_add_func("/lib/sdp_get_profile_descs/workaround",
- test_sdp_get_profile_descs_workaround);
+ tester_add("/lib/sdp_get_profile_descs/workaround", NULL, NULL,
+ test_sdp_get_profile_descs_workaround, NULL);

- g_test_add_func("/lib/sdp_get_server_ver", test_sdp_get_server_ver);
+ tester_add("/lib/sdp_get_server_ver", NULL, NULL,
+ test_sdp_get_server_ver, NULL);

- return g_test_run();
+ return tester_run();
}
--
1.9.1


2015-05-19 15:01:04

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 5/5] unit/test-uuid: Use tester framework

---
Makefile.am | 3 ++-
unit/test-uuid.c | 52 ++++++++++++++++++++++++++++++----------------------
2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f14539d..44d7893 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -273,7 +273,8 @@ unit_test_eir_LDADD = src/libshared-glib.la lib/libbluetooth-internal.la \
unit_tests += unit/test-uuid

unit_test_uuid_SOURCES = unit/test-uuid.c
-unit_test_uuid_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+unit_test_uuid_LDADD = src/libshared-glib.la lib/libbluetooth-internal.la \
+ @GLIB_LIBS@

unit_tests += unit/test-textfile

diff --git a/unit/test-uuid.c b/unit/test-uuid.c
index 60c4791..5f45b0c 100644
--- a/unit/test-uuid.c
+++ b/unit/test-uuid.c
@@ -29,6 +29,7 @@

#include "lib/bluetooth.h"
#include "lib/uuid.h"
+#include "src/shared/tester.h"

struct uuid_test_data {
const char *str;
@@ -128,8 +129,11 @@ static void test_uuid(gconstpointer data)
break;
case BT_UUID_UNSPEC:
default:
+ tester_test_passed();
return;
}
+
+ tester_test_passed();
}

static void test_str(gconstpointer data)
@@ -157,11 +161,13 @@ static void test_str(gconstpointer data)
bt_uuid32_create(&uuid, test_data->val32);
break;
default:
+ tester_test_passed();
return;
}

bt_uuid_to_string(&uuid, buf, sizeof(buf));
g_assert(strcasecmp(buf, str) == 0);
+ tester_test_passed();
}

static void test_cmp(gconstpointer data)
@@ -173,6 +179,7 @@ static void test_cmp(gconstpointer data)
g_assert(bt_string_to_uuid(&uuid2, test_data->str128) == 0);

g_assert(bt_uuid_cmp(&uuid1, &uuid2) == 0);
+ tester_test_passed();
}

static const struct uuid_test_data compress[] = {
@@ -220,43 +227,44 @@ static void test_malformed(gconstpointer data)
bt_uuid_t uuid;

g_assert(bt_string_to_uuid(&uuid, str) != 0);
+ tester_test_passed();
}

int main(int argc, char *argv[])
{
size_t i;

- g_test_init(&argc, &argv, NULL);
+ tester_init(&argc, &argv);

- g_test_add_data_func("/uuid/base", &uuid_base, test_uuid);
- g_test_add_data_func("/uuid/base/str", &uuid_base, test_str);
- g_test_add_data_func("/uuid/base/cmp", &uuid_base, test_cmp);
+ tester_add("/uuid/base", &uuid_base, NULL, test_uuid, NULL);
+ tester_add("/uuid/base/str", &uuid_base, NULL, test_str, NULL);
+ tester_add("/uuid/base/cmp", &uuid_base, NULL, test_cmp, NULL);

- g_test_add_data_func("/uuid/sixteen1", &uuid_sixteen1, test_uuid);
- g_test_add_data_func("/uuid/sixteen1/str", &uuid_sixteen1, test_str);
- g_test_add_data_func("/uuid/sixteen1/cmp", &uuid_sixteen1, test_cmp);
+ tester_add("/uuid/sixteen1", &uuid_sixteen1, NULL, test_uuid, NULL);
+ tester_add("/uuid/sixteen1/str", &uuid_sixteen1, NULL, test_str, NULL);
+ tester_add("/uuid/sixteen1/cmp", &uuid_sixteen1, NULL, test_cmp, NULL);

- g_test_add_data_func("/uuid/sixteen2", &uuid_sixteen2, test_uuid);
- g_test_add_data_func("/uuid/sixteen2/str", &uuid_sixteen2, test_str);
- g_test_add_data_func("/uuid/sixteen2/cmp", &uuid_sixteen2, test_cmp);
+ tester_add("/uuid/sixteen2", &uuid_sixteen2, NULL, test_uuid, NULL);
+ tester_add("/uuid/sixteen2/str", &uuid_sixteen2, NULL, test_str, NULL);
+ tester_add("/uuid/sixteen2/cmp", &uuid_sixteen2, NULL, test_cmp, NULL);

- g_test_add_data_func("/uuid/thirtytwo1", &uuid_32_1, test_uuid);
- g_test_add_data_func("/uuid/thirtytwo1/str", &uuid_32_1, test_str);
- g_test_add_data_func("/uuid/thirtytwo1/cmp", &uuid_32_1, test_cmp);
+ tester_add("/uuid/thirtytwo1", &uuid_32_1, NULL, test_uuid, NULL);
+ tester_add("/uuid/thirtytwo1/str", &uuid_32_1, NULL, test_str, NULL);
+ tester_add("/uuid/thirtytwo1/cmp", &uuid_32_1, NULL, test_cmp, NULL);

- g_test_add_data_func("/uuid/thirtytwo2", &uuid_32_2, test_uuid);
- g_test_add_data_func("/uuid/thritytwo2/str", &uuid_32_2, test_str);
- g_test_add_data_func("/uuid/thirtytwo2/cmp", &uuid_32_2, test_cmp);
+ tester_add("/uuid/thirtytwo2", &uuid_32_2, NULL, test_uuid, NULL);
+ tester_add("/uuid/thritytwo2/str", &uuid_32_2, NULL, test_str, NULL);
+ tester_add("/uuid/thirtytwo2/cmp", &uuid_32_2, NULL, test_cmp, NULL);

- g_test_add_data_func("/uuid/onetwentyeight", &uuid_128, test_uuid);
- g_test_add_data_func("/uuid/onetwentyeight/str", &uuid_128, test_str);
- g_test_add_data_func("/uuid/onetwentyeight/cmp", &uuid_128, test_cmp);
+ tester_add("/uuid/onetwentyeight", &uuid_128, NULL, test_uuid, NULL);
+ tester_add("/uuid/onetwentyeight/str", &uuid_128, NULL, test_str, NULL);
+ tester_add("/uuid/onetwentyeight/cmp", &uuid_128, NULL, test_cmp, NULL);

for (i = 0; malformed[i]; i++) {
char *testpath;

testpath = g_strdup_printf("/uuid/malformed/%s", malformed[i]);
- g_test_add_data_func(testpath, malformed[i], test_malformed);
+ tester_add(testpath, malformed[i], NULL, test_malformed, NULL);
g_free(testpath);
}

@@ -265,9 +273,9 @@ int main(int argc, char *argv[])

testpath = g_strdup_printf("/uuid/compress/%s",
compress[i].str);
- g_test_add_data_func(testpath, compress + i, test_uuid);
+ tester_add(testpath, compress + i, NULL, test_uuid, NULL);
g_free(testpath);
}

- return g_test_run();
+ return tester_run();
}
--
1.9.1


2015-05-19 15:01:02

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 3/5] unit/test-queue: Use tester framework

---
unit/test-queue.c | 55 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 34 insertions(+), 21 deletions(-)

diff --git a/unit/test-queue.c b/unit/test-queue.c
index 12319b0..d912a64 100644
--- a/unit/test-queue.c
+++ b/unit/test-queue.c
@@ -29,8 +29,9 @@

#include "src/shared/util.h"
#include "src/shared/queue.h"
+#include "src/shared/tester.h"

-static void test_basic(void)
+static void test_basic(const void *data)
{
struct queue *queue;
unsigned int n, i;
@@ -56,6 +57,7 @@ static void test_basic(void)
}

queue_destroy(queue, NULL);
+ tester_test_passed();
}

static void foreach_destroy(void *data, void *user_data)
@@ -65,7 +67,7 @@ static void foreach_destroy(void *data, void *user_data)
queue_destroy(queue, NULL);
}

-static void test_foreach_destroy(void)
+static void test_foreach_destroy(const void *data)
{
struct queue *queue;

@@ -76,6 +78,7 @@ static void test_foreach_destroy(void)
queue_push_tail(queue, UINT_TO_PTR(2));

queue_foreach(queue, foreach_destroy, queue);
+ tester_test_passed();
}

static void foreach_remove(void *data, void *user_data)
@@ -85,7 +88,7 @@ static void foreach_remove(void *data, void *user_data)
g_assert(queue_remove(queue, data));
}

-static void test_foreach_remove(void)
+static void test_foreach_remove(const void *data)
{
struct queue *queue;

@@ -97,6 +100,7 @@ static void test_foreach_remove(void)

queue_foreach(queue, foreach_remove, queue);
queue_destroy(queue, NULL);
+ tester_test_passed();
}

static void foreach_remove_all(void *data, void *user_data)
@@ -106,7 +110,7 @@ static void foreach_remove_all(void *data, void *user_data)
queue_remove_all(queue, NULL, NULL, NULL);
}

-static void test_foreach_remove_all(void)
+static void test_foreach_remove_all(const void *data)
{
struct queue *queue;

@@ -118,6 +122,7 @@ static void test_foreach_remove_all(void)

queue_foreach(queue, foreach_remove_all, queue);
queue_destroy(queue, NULL);
+ tester_test_passed();
}

static void foreach_remove_backward(void *data, void *user_data)
@@ -128,7 +133,7 @@ static void foreach_remove_backward(void *data, void *user_data)
queue_remove(queue, UINT_TO_PTR(1));
}

-static void test_foreach_remove_backward(void)
+static void test_foreach_remove_backward(const void *data)
{
struct queue *queue;

@@ -140,6 +145,7 @@ static void test_foreach_remove_backward(void)

queue_foreach(queue, foreach_remove_backward, queue);
queue_destroy(queue, NULL);
+ tester_test_passed();
}

static struct queue *static_queue;
@@ -149,7 +155,7 @@ static void destroy_remove(void *user_data)
queue_remove(static_queue, user_data);
}

-static void test_destroy_remove(void)
+static void test_destroy_remove(const void *data)
{
static_queue = queue_new();

@@ -159,9 +165,10 @@ static void test_destroy_remove(void)
queue_push_tail(static_queue, UINT_TO_PTR(2));

queue_destroy(static_queue, destroy_remove);
+ tester_test_passed();
}

-static void test_push_after(void)
+static void test_push_after(const void *data)
{
struct queue *queue;
unsigned int len, i;
@@ -212,6 +219,7 @@ static void test_push_after(void)
g_assert(queue_pop_head(queue) == UINT_TO_PTR(1));

queue_destroy(queue, NULL);
+ tester_test_passed();
}

static bool match_int(const void *a, const void *b)
@@ -227,7 +235,7 @@ static bool match_ptr(const void *a, const void *b)
return a == b;
}

-static void test_remove_all(void)
+static void test_remove_all(const void *data)
{
struct queue *queue;

@@ -248,21 +256,26 @@ static void test_remove_all(void)
g_assert(queue_isempty(queue));

queue_destroy(queue, NULL);
+ tester_test_passed();
}

int main(int argc, char *argv[])
{
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/queue/basic", test_basic);
- g_test_add_func("/queue/foreach_destroy", test_foreach_destroy);
- g_test_add_func("/queue/foreach_remove", test_foreach_remove);
- g_test_add_func("/queue/foreach_remove_all", test_foreach_remove_all);
- g_test_add_func("/queue/foreach_remove_backward",
- test_foreach_remove_backward);
- g_test_add_func("/queue/destroy_remove", test_destroy_remove);
- g_test_add_func("/queue/push_after", test_push_after);
- g_test_add_func("/queue/remove_all", test_remove_all);
-
- return g_test_run();
+ tester_init(&argc, &argv);
+
+ tester_add("/queue/basic", NULL, NULL, test_basic, NULL);
+ tester_add("/queue/foreach_destroy", NULL, NULL,
+ test_foreach_destroy, NULL);
+ tester_add("/queue/foreach_remove", NULL, NULL,
+ test_foreach_remove, NULL);
+ tester_add("/queue/foreach_remove_all", NULL, NULL,
+ test_foreach_remove_all, NULL);
+ tester_add("/queue/foreach_remove_backward", NULL, NULL,
+ test_foreach_remove_backward, NULL);
+ tester_add("/queue/destroy_remove", NULL, NULL,
+ test_destroy_remove, NULL);
+ tester_add("/queue/push_after", NULL, NULL, test_push_after, NULL);
+ tester_add("/queue/remove_all", NULL, NULL, test_remove_all, NULL);
+
+ return tester_run();
}
--
1.9.1


2015-05-19 15:01:01

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 2/5] unit/test-textfile: Use tester framework

---
Makefile.am | 2 +-
unit/test-textfile.c | 49 +++++++++++++++++++++++--------------------------
2 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 9e94648..6aa8410 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -278,7 +278,7 @@ unit_test_uuid_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
unit_tests += unit/test-textfile

unit_test_textfile_SOURCES = unit/test-textfile.c src/textfile.h src/textfile.c
-unit_test_textfile_LDADD = @GLIB_LIBS@
+unit_test_textfile_LDADD = src/libshared-glib.la @GLIB_LIBS@

unit_tests += unit/test-crc

diff --git a/unit/test-textfile.c b/unit/test-textfile.c
index d873df4..5250f98 100644
--- a/unit/test-textfile.c
+++ b/unit/test-textfile.c
@@ -34,6 +34,7 @@
#include <glib.h>

#include "src/textfile.h"
+#include "src/shared/tester.h"

static const char test_pathname[] = "/tmp/textfile";

@@ -79,7 +80,7 @@ done:
close(fd);
}

-static void test_pagesize(void)
+static void test_pagesize(const void *data)
{
char key[18], *str;
int size;
@@ -87,21 +88,20 @@ static void test_pagesize(void)
size = getpagesize();
g_assert(size >= 4096);

- if (g_test_verbose())
- g_print("System uses a page size of %d bytes\n", size);
+ tester_debug("System uses a page size of %d bytes\n", size);

util_create_pagesize();

sprintf(key, "11:11:11:11:11:11");
str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s\n", str);
+ tester_debug("%s\n", str);

g_assert(str == NULL);
+ tester_test_passed();
}

-static void test_delete(void)
+static void test_delete(const void *data)
{
char key[18], value[512], *str;

@@ -116,13 +116,13 @@ static void test_delete(void)
str = textfile_get(test_pathname, key);
g_assert(str != NULL);

- if (g_test_verbose())
- g_print("%s\n", str);
+ tester_debug("%s\n", str);

g_free(str);
+ tester_test_passed();
}

-static void test_overwrite(void)
+static void test_overwrite(const void *data)
{
char key[18], value[512], *str;

@@ -143,10 +143,10 @@ static void test_overwrite(void)

str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s\n", str);
+ tester_debug("%s\n", str);

g_assert(str == NULL);
+ tester_test_passed();
}

static void check_entry(char *key, char *value, void *data)
@@ -164,7 +164,7 @@ static void check_entry(char *key, char *value, void *data)
g_assert(strlen(value) == len);
}

-static void test_multiple(void)
+static void test_multiple(const void *data)
{
char key[18], value[512], *str;
unsigned int i, j, max = 10;
@@ -182,8 +182,7 @@ static void test_multiple(void)

str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s %s\n", key, str);
+ tester_debug("%s %s\n", key, str);

g_assert(str != NULL);
g_assert(strcmp(str, value) == 0);
@@ -201,8 +200,7 @@ static void test_multiple(void)

str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s %s\n", key, str);
+ tester_debug("%s %s\n", key, str);

g_assert(str != NULL);
g_assert(strcmp(str, value) == 0);
@@ -219,8 +217,7 @@ static void test_multiple(void)

str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s %s\n", key, str);
+ tester_debug("%s %s\n", key, str);

g_assert(str != NULL);
g_assert(strcmp(str, value) == 0);
@@ -231,8 +228,7 @@ static void test_multiple(void)
sprintf(key, "00:00:00:00:00:%02X", i);
str = textfile_get(test_pathname, key);

- if (g_test_verbose())
- g_print("%s %s\n", key, str);
+ tester_debug("%s %s\n", key, str);

g_assert(str != NULL);

@@ -262,16 +258,17 @@ static void test_multiple(void)
g_assert(textfile_del(test_pathname, key) == 0);

textfile_foreach(test_pathname, check_entry, GUINT_TO_POINTER(max));
+ tester_test_passed();
}

int main(int argc, char *argv[])
{
- g_test_init(&argc, &argv, NULL);
+ tester_init(&argc, &argv);

- g_test_add_func("/textfile/pagesize", test_pagesize);
- g_test_add_func("/textfile/delete", test_delete);
- g_test_add_func("/textfile/overwrite", test_overwrite);
- g_test_add_func("/textfile/multiple", test_multiple);
+ tester_add("/textfile/pagesize", NULL, NULL, test_pagesize, NULL);
+ tester_add("/textfile/delete", NULL, NULL, test_delete, NULL);
+ tester_add("/textfile/overwrite", NULL, NULL, test_overwrite, NULL);
+ tester_add("/textfile/multiple", NULL, NULL, test_multiple, NULL);

- return g_test_run();
+ return tester_run();
}
--
1.9.1


2015-05-19 15:01:00

by Gowtham Anandha Babu

[permalink] [raw]
Subject: [PATCH 1/5] unit/test-ringbuf: Use tester framework

---
unit/test-ringbuf.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/unit/test-ringbuf.c b/unit/test-ringbuf.c
index e28e04b..a97524e 100644
--- a/unit/test-ringbuf.c
+++ b/unit/test-ringbuf.c
@@ -32,6 +32,7 @@
#include <glib.h>

#include "src/shared/ringbuf.h"
+#include "src/shared/tester.h"

static unsigned int nlpo2(unsigned int x)
{
@@ -54,7 +55,7 @@ static unsigned int align_power2(unsigned int u)
return 1 << fls(u - 1);
}

-static void test_power2(void)
+static void test_power2(const void *data)
{
size_t i;

@@ -68,25 +69,25 @@ static void test_power2(void)
while (size3 < i && size3 < SIZE_MAX)
size3 <<= 1;

- if (g_test_verbose())
- g_print("%zu -> size1=%zu size2=%zu size3=%zu\n",
+ tester_debug("%zu -> size1=%zu size2=%zu size3=%zu\n",
i, size1, size2, size3);

g_assert(size1 == size2);
g_assert(size2 == size3);
g_assert(size3 == size1);
}
+
+ tester_test_passed();
}

-static void test_alloc(void)
+static void test_alloc(const void *data)
{
int i;

for (i = 2; i < 10000; i++) {
struct ringbuf *rb;

- if (g_test_verbose())
- g_print("Iteration %i\n", i);
+ tester_debug("Iteration %i\n", i);

rb = ringbuf_new(i);
g_assert(rb != NULL);
@@ -95,9 +96,11 @@ static void test_alloc(void)

ringbuf_free(rb);
}
+
+ tester_test_passed();
}

-static void test_printf(void)
+static void test_printf(const void *data)
{
static size_t rb_size = 500;
static size_t rb_capa = 512;
@@ -115,8 +118,7 @@ static void test_printf(void)
if (!count)
continue;

- if (g_test_verbose())
- g_print("Iteration %i\n", i);
+ tester_debug("Iteration %i\n", i);

len = asprintf(&str, "%*c", (int) count, 'x');
g_assert(len == count);
@@ -140,15 +142,16 @@ static void test_printf(void)
}

ringbuf_free(rb);
+ tester_test_passed();
}

int main(int argc, char *argv[])
{
- g_test_init(&argc, &argv, NULL);
+ tester_init(&argc, &argv);

- g_test_add_func("/ringbuf/power2", test_power2);
- g_test_add_func("/ringbuf/alloc", test_alloc);
- g_test_add_func("/ringbuf/printf", test_printf);
+ tester_add("/ringbuf/power2", NULL, NULL, test_power2, NULL);
+ tester_add("/ringbuf/alloc", NULL, NULL, test_alloc, NULL);
+ tester_add("/ringbuf/printf", NULL, NULL, test_printf, NULL);

- return g_test_run();
+ return tester_run();
}
--
1.9.1