Skip to content

Commit

Permalink
Adapt unit tests to 64-bit architecture
Browse files Browse the repository at this point in the history
This allows to run unit tests on 64-bit architecture.
This also modifies some mbuf tests, so the test pool buf size
is no longer hardcoded.
  • Loading branch information
m-gorecki committed Oct 24, 2023
1 parent d6afe7a commit 91ad909
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 53 deletions.
4 changes: 2 additions & 2 deletions fs/nffs/selftest/src/nffs_test_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
if (db.ndb_inode_id != NFFS_ID_NONE) {
nb.nb_inode_entry = nffs_hash_find_inode(db.ndb_inode_id);
} else {
nb.nb_inode_entry = (void*)db.ndb_inode_id;
nb.nb_inode_entry = (void *)(uintptr_t)db.ndb_inode_id;
}
if (db.ndb_prev_id != NFFS_ID_NONE) {
nb.nb_prev = nffs_hash_find_block(db.ndb_prev_id);
} else {
nb.nb_prev = (void*)db.ndb_prev_id;
nb.nb_prev = (void *)(uintptr_t)db.ndb_prev_id;
}
nb.nb_data_len = db.ndb_data_len;
}
Expand Down
6 changes: 1 addition & 5 deletions kernel/os/selftest/src/mbuf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
#include "testutil/testutil.h"
#include "os_test_priv.h"

/*
* NOTE: currently, the buffer size cannot be changed as some tests are
* hard-coded for this size.
*/
#define MBUF_TEST_POOL_BUF_SIZE (256)
#define MBUF_TEST_POOL_BUF_SIZE (320)
#define MBUF_TEST_POOL_BUF_COUNT (10)

#define MBUF_TEST_DATA_LEN (1024)
Expand Down
6 changes: 1 addition & 5 deletions kernel/os/selftest/src/mbuf_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
extern "C" {
#endif

/*
* NOTE: currently, the buffer size cannot be changed as some tests are
* hard-coded for this size.
*/
#define MBUF_TEST_POOL_BUF_SIZE (256)
#define MBUF_TEST_POOL_BUF_SIZE (320)
#define MBUF_TEST_POOL_BUF_COUNT (10)

#define MBUF_TEST_DATA_LEN (1024)
Expand Down
36 changes: 23 additions & 13 deletions kernel/os/selftest/src/testcases/ob_mbuf_test_adj.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
TEST_CASE_SELF(os_mbuf_test_adj)
{
struct os_mbuf *om;
int initial_om_len;
int om_len_check;
int pkthdr_len_check;
int rc;

os_mbuf_test_setup();
Expand All @@ -31,30 +34,37 @@ TEST_CASE_SELF(os_mbuf_test_adj)
rc = os_mbuf_append(om, os_mbuf_test_data, sizeof os_mbuf_test_data);
TEST_ASSERT_FATAL(rc == 0);

os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 222,
sizeof os_mbuf_test_data, 18);
initial_om_len = MBUF_TEST_POOL_BUF_SIZE - sizeof(struct os_mbuf) -
sizeof(struct os_mbuf_pkthdr) - 10;
pkthdr_len_check = 10 + sizeof(struct os_mbuf_pkthdr);
om_len_check = initial_om_len;

os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, om_len_check,
sizeof os_mbuf_test_data, pkthdr_len_check);

/* Remove from the front. */
os_mbuf_adj(om, 10);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
sizeof os_mbuf_test_data - 10, 18);
om_len_check -= 10;
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, om_len_check,
sizeof os_mbuf_test_data - 10, pkthdr_len_check);

/* Remove from the back. */
os_mbuf_adj(om, -10);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
sizeof os_mbuf_test_data - 20, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, om_len_check,
sizeof os_mbuf_test_data - 20, pkthdr_len_check);

/* Remove entire first buffer. */
os_mbuf_adj(om, 212);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 222, 0,
sizeof os_mbuf_test_data - 232, 18);
os_mbuf_adj(om, om_len_check);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + initial_om_len, 0,
sizeof os_mbuf_test_data - initial_om_len - 10,
pkthdr_len_check);

/* Remove next buffer. */
os_mbuf_adj(om, 256);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 478, 0,
sizeof os_mbuf_test_data - 488, 18);
os_mbuf_adj(om, MBUF_TEST_POOL_BUF_SIZE);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + initial_om_len + MBUF_TEST_POOL_BUF_SIZE, 0,
sizeof os_mbuf_test_data - (initial_om_len + MBUF_TEST_POOL_BUF_SIZE + 10), pkthdr_len_check);

/* Remove more data than is present. */
os_mbuf_adj(om, 1000);
os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, pkthdr_len_check);
}
13 changes: 8 additions & 5 deletions kernel/os/selftest/src/testcases/ob_mbuf_test_pullup.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TEST_CASE_SELF(os_mbuf_test_pullup)
{
struct os_mbuf *om;
struct os_mbuf *om2;
int pkthdr_len_check;
int rc;

os_mbuf_test_setup();
Expand All @@ -30,6 +31,8 @@ TEST_CASE_SELF(os_mbuf_test_pullup)
om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
TEST_ASSERT_FATAL(om != NULL);

pkthdr_len_check = 10 + sizeof(struct os_mbuf_pkthdr);

om = os_mbuf_pullup(om, 1);
TEST_ASSERT(om == NULL);

Expand All @@ -39,10 +42,10 @@ TEST_CASE_SELF(os_mbuf_test_pullup)

rc = os_mbuf_append(om, os_mbuf_test_data, 1);
TEST_ASSERT_FATAL(rc == 0);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, pkthdr_len_check);

om = os_mbuf_pullup(om, 1);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, pkthdr_len_check);

/*** Spread os_mbuf_test_data across four mbufs. */
om2 = os_mbuf_get(&os_mbuf_pool, 10);
Expand All @@ -66,7 +69,7 @@ TEST_CASE_SELF(os_mbuf_test_pullup)
TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(om) == 4);

om = os_mbuf_pullup(om, 4);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 4, 4, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 4, 4, pkthdr_len_check);

os_mbuf_free_chain(om);

Expand All @@ -85,7 +88,7 @@ TEST_CASE_SELF(os_mbuf_test_pullup)
os_mbuf_concat(om, om2);

om = os_mbuf_pullup(om, 200);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, pkthdr_len_check);

/*** Partial pullup. */
om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
Expand All @@ -102,5 +105,5 @@ TEST_CASE_SELF(os_mbuf_test_pullup)
os_mbuf_concat(om, om2);

om = os_mbuf_pullup(om, 150);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 150, 200, 18);
os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 150, 200, pkthdr_len_check);
}
56 changes: 36 additions & 20 deletions kernel/os/selftest/src/testcases/os_mbuf_test_extend.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,70 +22,86 @@ TEST_CASE_SELF(os_mbuf_test_extend)
{
struct os_mbuf *om;
void *v;
int trailingspace_check;
int om_len_check;
int pkthdr_len_check;

os_mbuf_test_setup();

/*** Series of successful extensions. */
om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
TEST_ASSERT_FATAL(om != NULL);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 222);
trailingspace_check = MBUF_TEST_POOL_BUF_SIZE - sizeof(struct os_mbuf) -
sizeof(struct os_mbuf_pkthdr) - 10;
om_len_check = 0;
pkthdr_len_check = 10 + sizeof(struct os_mbuf_pkthdr);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check, pkthdr_len_check);

v = os_mbuf_extend(om, 20);
trailingspace_check -= 20;
om_len_check += 20;
TEST_ASSERT(v != NULL);
TEST_ASSERT(v == om->om_data);
TEST_ASSERT(om->om_len == 20);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 202);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
os_mbuf_test_misc_assert_sane(om, NULL, 20, 20, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check, pkthdr_len_check);

v = os_mbuf_extend(om, 100);
trailingspace_check -= 100;
om_len_check += 100;
TEST_ASSERT(v != NULL);
TEST_ASSERT(v == om->om_data + 20);
TEST_ASSERT(om->om_len == 120);
TEST_ASSERT(om->om_len == om_len_check);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 102);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
os_mbuf_test_misc_assert_sane(om, NULL, 120, 120, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check, pkthdr_len_check);

v = os_mbuf_extend(om, 101);
trailingspace_check -= 101;
om_len_check += 101;
TEST_ASSERT(v != NULL);
TEST_ASSERT(v == om->om_data + 120);
TEST_ASSERT(om->om_len == 221);
TEST_ASSERT(om->om_len == om_len_check);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 1);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
os_mbuf_test_misc_assert_sane(om, NULL, 221, 221, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check, pkthdr_len_check);

v = os_mbuf_extend(om, 1);
v = os_mbuf_extend(om, trailingspace_check);
om_len_check += trailingspace_check;
trailingspace_check = 0;
TEST_ASSERT(v != NULL);
TEST_ASSERT(v == om->om_data + 221);
TEST_ASSERT(om->om_len == 222);
TEST_ASSERT(om->om_len == om_len_check);

TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
os_mbuf_test_misc_assert_sane(om, NULL, 222, 222, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check, pkthdr_len_check);

/* Overflow into next buffer. */
v = os_mbuf_extend(om, 1);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == trailingspace_check);
TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);

TEST_ASSERT(v == SLIST_NEXT(om, om_next)->om_data);
TEST_ASSERT(om->om_len == 222);
TEST_ASSERT(om->om_len == om_len_check);
TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check + 1, pkthdr_len_check);

/*** Attempt to extend by an amount larger than max buf size fails. */
v = os_mbuf_extend(om, 257);
v = os_mbuf_extend(om, MBUF_TEST_POOL_BUF_SIZE + 1);
TEST_ASSERT(v == NULL);
TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);

TEST_ASSERT(om->om_len == 222);
TEST_ASSERT(om->om_len == om_len_check);
TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
os_mbuf_test_misc_assert_sane(om, NULL, om_len_check, om_len_check + 1, pkthdr_len_check);
}
3 changes: 0 additions & 3 deletions kernel/os/selftest/src/testcases/os_mbuf_test_pack_chains.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
#include "os_test_priv.h"

#if MBUF_TEST_POOL_BUF_SIZE != 256
#error "Test pool buffer size must be 256!"
#endif

/* This structure is used to create mbuf chains. It contains the length
of data that should be in each mbuf in the chain and the amount of
Expand Down

0 comments on commit 91ad909

Please sign in to comment.