* [PATCH 1/4] testsuite: add test for hash_add_unique
@ 2015-01-21 11:37 Caio Marcelo de Oliveira Filho
2015-01-21 11:37 ` [PATCH 2/4] testsuite: add test for growing then shrinking a hash Caio Marcelo de Oliveira Filho
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-01-21 11:37 UTC (permalink / raw)
To: linux-modules
---
testsuite/test-hash.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/testsuite/test-hash.c b/testsuite/test-hash.c
index 3cf5ba7..ea39b80 100644
--- a/testsuite/test-hash.c
+++ b/testsuite/test-hash.c
@@ -220,4 +220,30 @@ static int test_hash_free(const struct test *t)
DEFINE_TEST(test_hash_free,
.description = "test hash_free calling free function for all values");
+
+static int test_hash_add_unique(const struct test *t)
+{
+ const char *k[] = { "k1", "k2", "k3", "k4", "k5" };
+ const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
+ unsigned int i, j, N;
+
+ N = ARRAY_SIZE(k);
+ for (i = 0; i < N; i++) {
+ /* With 4 buckets, there'll be a bucket with more than one key. */
+ struct hash *h = hash_new(4, NULL);
+
+ /* Add the keys in different orders. */
+ for (j = 0; j < N; j++) {
+ unsigned int idx = (j + i) % N;
+ hash_add_unique(h, k[idx], v[idx]);
+ }
+
+ assert_return(hash_get_count(h) == N, EXIT_FAILURE);
+ hash_free(h);
+ }
+ return 0;
+}
+DEFINE_TEST(test_hash_add_unique,
+ .description = "test hash_add_unique with different key orders")
+
TESTSUITE_MAIN();
--
2.2.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] testsuite: add test for growing then shrinking a hash
2015-01-21 11:37 [PATCH 1/4] testsuite: add test for hash_add_unique Caio Marcelo de Oliveira Filho
@ 2015-01-21 11:37 ` Caio Marcelo de Oliveira Filho
2015-01-21 12:20 ` Lucas De Marchi
2015-01-21 11:37 ` [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test Caio Marcelo de Oliveira Filho
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-01-21 11:37 UTC (permalink / raw)
To: linux-modules
---
testsuite/test-hash.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/testsuite/test-hash.c b/testsuite/test-hash.c
index ea39b80..2e65f86 100644
--- a/testsuite/test-hash.c
+++ b/testsuite/test-hash.c
@@ -246,4 +246,37 @@ static int test_hash_add_unique(const struct test *t)
DEFINE_TEST(test_hash_add_unique,
.description = "test hash_add_unique with different key orders")
+
+static int test_hash_massive_add_del(const struct test *t)
+{
+ char buf[1024 * 8];
+ char *k;
+ struct hash *h;
+ unsigned int i, N = 1024;
+
+ h = hash_new(8, NULL);
+
+ k = &buf[0];
+ for (i = 0; i < N; i++) {
+ snprintf(k, 8, "k%d", i);
+ hash_add(h, k, k);
+ k += 8;
+ }
+
+ assert_return(hash_get_count(h) == N, EXIT_FAILURE);
+
+ k = &buf[0];
+ for (i = 0; i < N; i++) {
+ hash_del(h, k);
+ k += 8;
+ }
+
+ assert_return(hash_get_count(h) == 0, EXIT_FAILURE);
+
+ hash_free(h);
+ return 0;
+}
+DEFINE_TEST(test_hash_massive_add_del,
+ .description = "test multiple adds followed by multiple dels")
+
TESTSUITE_MAIN();
--
2.2.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test
2015-01-21 11:37 [PATCH 1/4] testsuite: add test for hash_add_unique Caio Marcelo de Oliveira Filho
2015-01-21 11:37 ` [PATCH 2/4] testsuite: add test for growing then shrinking a hash Caio Marcelo de Oliveira Filho
@ 2015-01-21 11:37 ` Caio Marcelo de Oliveira Filho
2015-01-21 12:20 ` Lucas De Marchi
2015-01-21 11:37 ` [PATCH 4/4] util: remove dead code in freadline_wrapped Caio Marcelo de Oliveira Filho
2015-01-21 12:17 ` [PATCH 1/4] testsuite: add test for hash_add_unique Lucas De Marchi
3 siblings, 1 reply; 8+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-01-21 11:37 UTC (permalink / raw)
To: linux-modules
---
testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt | 4 ++++
testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt | 2 ++
2 files changed, 6 insertions(+)
diff --git a/testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt b/testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt
index 87344ab..80c671b 100644
--- a/testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt
+++ b/testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt
@@ -4,3 +4,7 @@ this is a single line
1
three line lines in a row
3
+this line has exactly 256 chars to make fun with the implementation, so it must have word after word after word after word after word after word after word after word after word after word after word after word after word after word until it hits 256 chars
+1
+this line is very large because it has word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word until it hits 2015 chars
+1
diff --git a/testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt b/testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt
index f84a852..1c81f91 100644
--- a/testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt
+++ b/testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt
@@ -4,3 +4,5 @@ this is a single line
three line \
lines \
in a row
+this line has exactly 256 chars to make fun with the implementation, so it must have word after word after word after word after word after word after word after word after word after word after word after word after word after word until it hits 256 chars
+this line is very large because it has word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word after word until it hits 2015 chars
--
2.2.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] util: remove dead code in freadline_wrapped
2015-01-21 11:37 [PATCH 1/4] testsuite: add test for hash_add_unique Caio Marcelo de Oliveira Filho
2015-01-21 11:37 ` [PATCH 2/4] testsuite: add test for growing then shrinking a hash Caio Marcelo de Oliveira Filho
2015-01-21 11:37 ` [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test Caio Marcelo de Oliveira Filho
@ 2015-01-21 11:37 ` Caio Marcelo de Oliveira Filho
2015-01-21 12:21 ` Lucas De Marchi
2015-01-21 12:17 ` [PATCH 1/4] testsuite: add test for hash_add_unique Lucas De Marchi
3 siblings, 1 reply; 8+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-01-21 11:37 UTC (permalink / raw)
To: linux-modules
Each loop iteration starts with 'i < size'. When i is changed
the invariant is kept by checking if 'i == size' and growing the
buffer.
---
shared/util.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/shared/util.c b/shared/util.c
index 479f0fe..1a2b17c 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -314,13 +314,7 @@ char *freadline_wrapped(FILE *fp, unsigned int *linenum)
n++;
{
- char *ret;
- if (i == size) {
- ret = realloc(buf, size + 1);
- if (!ret)
- return NULL;
- } else
- ret = buf;
+ char *ret = buf;
ret[i] = '\0';
buf = NULL;
if (linenum)
--
2.2.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] testsuite: add test for hash_add_unique
2015-01-21 11:37 [PATCH 1/4] testsuite: add test for hash_add_unique Caio Marcelo de Oliveira Filho
` (2 preceding siblings ...)
2015-01-21 11:37 ` [PATCH 4/4] util: remove dead code in freadline_wrapped Caio Marcelo de Oliveira Filho
@ 2015-01-21 12:17 ` Lucas De Marchi
3 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2015-01-21 12:17 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
On Wed, Jan 21, 2015 at 9:37 AM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> ---
> testsuite/test-hash.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/testsuite/test-hash.c b/testsuite/test-hash.c
> index 3cf5ba7..ea39b80 100644
> --- a/testsuite/test-hash.c
> +++ b/testsuite/test-hash.c
> @@ -220,4 +220,30 @@ static int test_hash_free(const struct test *t)
> DEFINE_TEST(test_hash_free,
> .description = "test hash_free calling free function for all values");
>
> +
> +static int test_hash_add_unique(const struct test *t)
> +{
> + const char *k[] = { "k1", "k2", "k3", "k4", "k5" };
> + const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
> + unsigned int i, j, N;
> +
> + N = ARRAY_SIZE(k);
> + for (i = 0; i < N; i++) {
> + /* With 4 buckets, there'll be a bucket with more than one key. */
> + struct hash *h = hash_new(4, NULL);
Applied with 's/4/N - 1/' here
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/4] testsuite: add test for growing then shrinking a hash
2015-01-21 11:37 ` [PATCH 2/4] testsuite: add test for growing then shrinking a hash Caio Marcelo de Oliveira Filho
@ 2015-01-21 12:20 ` Lucas De Marchi
0 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2015-01-21 12:20 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
On Wed, Jan 21, 2015 at 9:37 AM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> ---
> testsuite/test-hash.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
Applied.
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test
2015-01-21 11:37 ` [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test Caio Marcelo de Oliveira Filho
@ 2015-01-21 12:20 ` Lucas De Marchi
0 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2015-01-21 12:20 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
On Wed, Jan 21, 2015 at 9:37 AM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> ---
> testsuite/rootfs-pristine/test-util/freadline_wrapped-correct.txt | 4 ++++
> testsuite/rootfs-pristine/test-util/freadline_wrapped-input.txt | 2 ++
> 2 files changed, 6 insertions(+)
Applied.
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 4/4] util: remove dead code in freadline_wrapped
2015-01-21 11:37 ` [PATCH 4/4] util: remove dead code in freadline_wrapped Caio Marcelo de Oliveira Filho
@ 2015-01-21 12:21 ` Lucas De Marchi
0 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2015-01-21 12:21 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
On Wed, Jan 21, 2015 at 9:37 AM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> Each loop iteration starts with 'i < size'. When i is changed
> the invariant is kept by checking if 'i == size' and growing the
> buffer.
> ---
> shared/util.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
Applied
--
Lucas De Marchi
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-01-21 12:21 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-21 11:37 [PATCH 1/4] testsuite: add test for hash_add_unique Caio Marcelo de Oliveira Filho
2015-01-21 11:37 ` [PATCH 2/4] testsuite: add test for growing then shrinking a hash Caio Marcelo de Oliveira Filho
2015-01-21 12:20 ` Lucas De Marchi
2015-01-21 11:37 ` [PATCH 3/4] testsuite: add more input cases to freadline_wrapped test Caio Marcelo de Oliveira Filho
2015-01-21 12:20 ` Lucas De Marchi
2015-01-21 11:37 ` [PATCH 4/4] util: remove dead code in freadline_wrapped Caio Marcelo de Oliveira Filho
2015-01-21 12:21 ` Lucas De Marchi
2015-01-21 12:17 ` [PATCH 1/4] testsuite: add test for hash_add_unique Lucas De Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).