clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -35,13 +35,7 @@
#define NUMNAMES 7
static const char *const names[NUMNAMES] = {
"Aillard",
"Aldaran",
"Alton",
"Ardais",
"Elhalyn",
"Hastur",
"Ridenow",
"Aillard", "Aldaran", "Alton", "Ardais", "Elhalyn", "Hastur", "Ridenow",
};
static struct thread *fakethreads[NUMNAMES];
@@ -54,290 +48,257 @@ static struct thread *fakethreads[NUMNAMES];
/*
* Create a dummy struct thread that we can put on lists for testing.
*/
static
struct thread *
fakethread_create(const char *name)
{
struct thread *t;
static struct thread *fakethread_create(const char *name) {
struct thread *t;
t = kmalloc(sizeof(*t));
if (t == NULL) {
panic("threadlisttest: Out of memory\n");
}
/* ignore most of the fields, zero everything for tidiness */
bzero(t, sizeof(*t));
t->t_name = kstrdup(name);
if (t->t_name == NULL) {
panic("threadlisttest: Out of memory\n");
}
t->t_stack = FAKE_MAGIC;
threadlistnode_init(&t->t_listnode, t);
return t;
t = kmalloc(sizeof(*t));
if (t == NULL) {
panic("threadlisttest: Out of memory\n");
}
/* ignore most of the fields, zero everything for tidiness */
bzero(t, sizeof(*t));
t->t_name = kstrdup(name);
if (t->t_name == NULL) {
panic("threadlisttest: Out of memory\n");
}
t->t_stack = FAKE_MAGIC;
threadlistnode_init(&t->t_listnode, t);
return t;
}
/*
* Destroy a fake thread.
*/
static
void
fakethread_destroy(struct thread *t)
{
KASSERT(t->t_stack == FAKE_MAGIC);
threadlistnode_cleanup(&t->t_listnode);
kfree(t->t_name);
kfree(t);
static void fakethread_destroy(struct thread *t) {
KASSERT(t->t_stack == FAKE_MAGIC);
threadlistnode_cleanup(&t->t_listnode);
kfree(t->t_name);
kfree(t);
}
////////////////////////////////////////////////////////////
// support stuff
static
void
check_order(struct threadlist *tl, bool rev)
{
const char string0[] = "...";
const char stringN[] = "~~~";
static void check_order(struct threadlist *tl, bool rev) {
const char string0[] = "...";
const char stringN[] = "~~~";
struct thread *t;
const char *first = rev ? stringN : string0;
const char *last = rev ? string0 : stringN;
const char *prev;
int cmp;
struct thread *t;
const char *first = rev ? stringN : string0;
const char *last = rev ? string0 : stringN;
const char *prev;
int cmp;
prev = first;
THREADLIST_FORALL(t, *tl) {
cmp = strcmp(prev, t->t_name);
KASSERT(rev ? (cmp > 0) : (cmp < 0));
prev = t->t_name;
}
cmp = strcmp(prev, last);
KASSERT(rev ? (cmp > 0) : (cmp < 0));
prev = first;
THREADLIST_FORALL(t, *tl) {
cmp = strcmp(prev, t->t_name);
KASSERT(rev ? (cmp > 0) : (cmp < 0));
prev = t->t_name;
}
cmp = strcmp(prev, last);
KASSERT(rev ? (cmp > 0) : (cmp < 0));
}
////////////////////////////////////////////////////////////
// tests
static
void
threadlisttest_a(void)
{
struct threadlist tl;
static void threadlisttest_a(void) {
struct threadlist tl;
threadlist_init(&tl);
KASSERT(threadlist_isempty(&tl));
threadlist_cleanup(&tl);
threadlist_init(&tl);
KASSERT(threadlist_isempty(&tl));
threadlist_cleanup(&tl);
}
static
void
threadlisttest_b(void)
{
struct threadlist tl;
struct thread *t;
static void threadlisttest_b(void) {
struct threadlist tl;
struct thread *t;
threadlist_init(&tl);
threadlist_init(&tl);
threadlist_addhead(&tl, fakethreads[0]);
check_order(&tl, false);
check_order(&tl, true);
KASSERT(tl.tl_count == 1);
t = threadlist_remhead(&tl);
KASSERT(tl.tl_count == 0);
KASSERT(t == fakethreads[0]);
threadlist_addhead(&tl, fakethreads[0]);
check_order(&tl, false);
check_order(&tl, true);
KASSERT(tl.tl_count == 1);
t = threadlist_remhead(&tl);
KASSERT(tl.tl_count == 0);
KASSERT(t == fakethreads[0]);
threadlist_addtail(&tl, fakethreads[0]);
check_order(&tl, false);
check_order(&tl, true);
KASSERT(tl.tl_count == 1);
t = threadlist_remtail(&tl);
KASSERT(tl.tl_count == 0);
KASSERT(t == fakethreads[0]);
threadlist_addtail(&tl, fakethreads[0]);
check_order(&tl, false);
check_order(&tl, true);
KASSERT(tl.tl_count == 1);
t = threadlist_remtail(&tl);
KASSERT(tl.tl_count == 0);
KASSERT(t == fakethreads[0]);
threadlist_cleanup(&tl);
threadlist_cleanup(&tl);
}
static
void
threadlisttest_c(void)
{
struct threadlist tl;
struct thread *t;
static void threadlisttest_c(void) {
struct threadlist tl;
struct thread *t;
threadlist_init(&tl);
threadlist_init(&tl);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addhead(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addhead(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
check_order(&tl, true);
check_order(&tl, true);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
threadlist_addtail(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
threadlist_addtail(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
check_order(&tl, false);
check_order(&tl, false);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
threadlist_cleanup(&tl);
threadlist_cleanup(&tl);
}
static
void
threadlisttest_d(void)
{
struct threadlist tl;
struct thread *t;
static void threadlisttest_d(void) {
struct threadlist tl;
struct thread *t;
threadlist_init(&tl);
threadlist_init(&tl);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
check_order(&tl, false);
check_order(&tl, false);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[0]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
KASSERT(tl.tl_count == 0);
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[0]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
KASSERT(tl.tl_count == 0);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
threadlist_addhead(&tl, fakethreads[0]);
threadlist_addtail(&tl, fakethreads[1]);
KASSERT(tl.tl_count == 2);
check_order(&tl, false);
check_order(&tl, false);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[1]);
t = threadlist_remtail(&tl);
KASSERT(t == fakethreads[0]);
KASSERT(tl.tl_count == 0);
threadlist_cleanup(&tl);
threadlist_cleanup(&tl);
}
static
void
threadlisttest_e(void)
{
struct threadlist tl;
struct thread *t;
unsigned i;
static void threadlisttest_e(void) {
struct threadlist tl;
struct thread *t;
unsigned i;
threadlist_init(&tl);
threadlist_init(&tl);
threadlist_addhead(&tl, fakethreads[1]);
threadlist_addtail(&tl, fakethreads[3]);
KASSERT(tl.tl_count == 2);
check_order(&tl, false);
threadlist_addhead(&tl, fakethreads[1]);
threadlist_addtail(&tl, fakethreads[3]);
KASSERT(tl.tl_count == 2);
check_order(&tl, false);
threadlist_insertafter(&tl, fakethreads[3], fakethreads[4]);
KASSERT(tl.tl_count == 3);
check_order(&tl, false);
threadlist_insertafter(&tl, fakethreads[3], fakethreads[4]);
KASSERT(tl.tl_count == 3);
check_order(&tl, false);
threadlist_insertbefore(&tl, fakethreads[0], fakethreads[1]);
KASSERT(tl.tl_count == 4);
check_order(&tl, false);
threadlist_insertbefore(&tl, fakethreads[0], fakethreads[1]);
KASSERT(tl.tl_count == 4);
check_order(&tl, false);
threadlist_insertafter(&tl, fakethreads[1], fakethreads[2]);
KASSERT(tl.tl_count == 5);
check_order(&tl, false);
threadlist_insertafter(&tl, fakethreads[1], fakethreads[2]);
KASSERT(tl.tl_count == 5);
check_order(&tl, false);
KASSERT(fakethreads[4]->t_listnode.tln_prev->tln_self ==
fakethreads[3]);
KASSERT(fakethreads[3]->t_listnode.tln_prev->tln_self ==
fakethreads[2]);
KASSERT(fakethreads[2]->t_listnode.tln_prev->tln_self ==
fakethreads[1]);
KASSERT(fakethreads[1]->t_listnode.tln_prev->tln_self ==
fakethreads[0]);
KASSERT(fakethreads[4]->t_listnode.tln_prev->tln_self == fakethreads[3]);
KASSERT(fakethreads[3]->t_listnode.tln_prev->tln_self == fakethreads[2]);
KASSERT(fakethreads[2]->t_listnode.tln_prev->tln_self == fakethreads[1]);
KASSERT(fakethreads[1]->t_listnode.tln_prev->tln_self == fakethreads[0]);
for (i=0; i<5; i++) {
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[i]);
}
KASSERT(tl.tl_count == 0);
for (i = 0; i < 5; i++) {
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[i]);
}
KASSERT(tl.tl_count == 0);
threadlist_cleanup(&tl);
threadlist_cleanup(&tl);
}
static
void
threadlisttest_f(void)
{
struct threadlist tl;
struct thread *t;
unsigned i;
static void threadlisttest_f(void) {
struct threadlist tl;
struct thread *t;
unsigned i;
threadlist_init(&tl);
threadlist_init(&tl);
for (i=0; i<NUMNAMES; i++) {
threadlist_addtail(&tl, fakethreads[i]);
}
KASSERT(tl.tl_count == NUMNAMES);
for (i = 0; i < NUMNAMES; i++) {
threadlist_addtail(&tl, fakethreads[i]);
}
KASSERT(tl.tl_count == NUMNAMES);
i=0;
THREADLIST_FORALL(t, tl) {
KASSERT(t == fakethreads[i]);
i++;
}
KASSERT(i == NUMNAMES);
i = 0;
THREADLIST_FORALL(t, tl) {
KASSERT(t == fakethreads[i]);
i++;
}
KASSERT(i == NUMNAMES);
i=0;
THREADLIST_FORALL_REV(t, tl) {
KASSERT(t == fakethreads[NUMNAMES - i - 1]);
i++;
}
KASSERT(i == NUMNAMES);
i = 0;
THREADLIST_FORALL_REV(t, tl) {
KASSERT(t == fakethreads[NUMNAMES - i - 1]);
i++;
}
KASSERT(i == NUMNAMES);
for (i=0; i<NUMNAMES; i++) {
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[i]);
}
KASSERT(tl.tl_count == 0);
for (i = 0; i < NUMNAMES; i++) {
t = threadlist_remhead(&tl);
KASSERT(t == fakethreads[i]);
}
KASSERT(tl.tl_count == 0);
}
////////////////////////////////////////////////////////////
// external interface
int
threadlisttest(int nargs, char **args)
{
unsigned i;
int threadlisttest(int nargs, char **args) {
unsigned i;
(void)nargs;
(void)args;
(void)nargs;
(void)args;
kprintf("Testing threadlists...\n");
kprintf("Testing threadlists...\n");
for (i=0; i<NUMNAMES; i++) {
fakethreads[i] = fakethread_create(names[i]);
}
for (i = 0; i < NUMNAMES; i++) {
fakethreads[i] = fakethread_create(names[i]);
}
threadlisttest_a();
threadlisttest_b();
threadlisttest_c();
threadlisttest_d();
threadlisttest_e();
threadlisttest_f();
threadlisttest_a();
threadlisttest_b();
threadlisttest_c();
threadlisttest_d();
threadlisttest_e();
threadlisttest_f();
for (i=0; i<NUMNAMES; i++) {
fakethread_destroy(fakethreads[i]);
fakethreads[i] = NULL;
}
for (i = 0; i < NUMNAMES; i++) {
fakethread_destroy(fakethreads[i]);
fakethreads[i] = NULL;
}
kprintf("Done.\n");
return 0;
kprintf("Done.\n");
return 0;
}