Trying to get closer to the original OS/161 sources.

This commit is contained in:
Geoffrey Challen 2016-01-11 20:54:52 -05:00
parent 202cc3eab4
commit a6878c822b
13 changed files with 164 additions and 161 deletions

View File

@ -437,11 +437,13 @@ file test/synchtest.c
file test/semunit.c
file test/kmalloctest.c
file test/fstest.c
file test/lib.c
optfile net test/nettest.c
defoption synchprobs
optfile synchprobs synchprobs/whalemating.c
optfile synchprobs synchprobs/stoplight.c
optfile synchprobs test/whalemating.c
optfile synchprobs test/stoplight.c
optfile synchprobs test/synchprobs.c
defoption automationtest

View File

@ -194,16 +194,5 @@ void kprintf_bootstrap(void);
#define DIVROUNDUP(a,b) (((a)+(b)-1)/(b))
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*b)
void random_yielder(uint32_t);
void random_spinner(uint32_t);
/*
* Testing variants of kprintf. tprintf is silent during automated testing.
* sprintf prefixes the kernel secret to kprintf messages during automated
* testing. nprintf is not silent during automated testing.
*/
int tkprintf(const char *format, ...) __PF(1,2);
int nkprintf(const char *format, ...) __PF(1,2);
#endif /* _LIB_H_ */

View File

@ -62,7 +62,7 @@ typedef __va_list va_list;
* or split the definition of va_list into another header file, none
* of which seems entirely desirable.
*/
int vkprintf(const char *fmt, va_list ap) __PF(1,0);
void vkprintf(const char *fmt, va_list ap) __PF(1,0);
int vsnprintf(char *buf, size_t maxlen, const char *fmt, va_list ap) __PF(3,0);
/*

View File

@ -1,28 +0,0 @@
#ifndef _SYNCHPROBS_H_
#define _SYNCHPROBS_H_
/*
* Synchronization problem primitives.
*/
/*
* whalemating.c.
*/
void whalemating_init(void);
void whalemating_cleanup(void);
void male(void);
void female(void);
void matchmaker(void);
/*
* stoplight.c.
*/
void gostraight(uint32_t);
void turnleft(uint32_t);
void turnright(uint32_t);
void stoplight_init(void);
void stoplight_cleanup(void);
#endif /* _SYNCHPROBS_H_ */

View File

@ -30,6 +30,9 @@
#ifndef _TEST_H_
#define _TEST_H_
/* Get __PF() for declaring printf-like functions. */
#include <cdefs.h>
#include "opt-synchprobs.h"
#include "opt-automationtest.h"
@ -126,6 +129,30 @@ void inQuadrant(int);
void leaveIntersection(void);
int stoplight(int, char **);
/*
* Synchronization problem primitives.
*/
/*
* whalemating.c.
*/
void whalemating_init(void);
void whalemating_cleanup(void);
void male(void);
void female(void);
void matchmaker(void);
/*
* stoplight.c.
*/
void gostraight(uint32_t);
void turnleft(uint32_t);
void turnright(uint32_t);
void stoplight_init(void);
void stoplight_cleanup(void);
#endif
/*
@ -138,4 +165,16 @@ int ll1test(int, char **);
int ll16test(int, char **);
#endif
void random_yielder(uint32_t);
void random_spinner(uint32_t);
/*
* Testing variants of kprintf. tprintf is silent during automated testing.
* sprintf prefixes the kernel secret to kprintf messages during automated
* testing. nprintf is not silent during automated testing.
*/
int tkprintf(const char *format, ...) __PF(1,2);
int nkprintf(const char *format, ...) __PF(1,2);
#endif /* _TEST_H_ */

View File

@ -40,6 +40,7 @@
#include <vfs.h> // for vfs_sync()
#include <lamebus/ltrace.h> // for ltrace_stop()
#include <kern/secret.h>
#include <test.h>
/* Flags word for DEBUG() macro. */
@ -93,9 +94,10 @@ console_send(void *junk, const char *data, size_t len)
/*
* kprintf and tprintf helper function.
*/
static
inline
int
vkprintf(const char *fmt, va_list ap)
__kprintf(const char *fmt, va_list ap)
{
int chars;
bool dolock;
@ -134,7 +136,7 @@ kprintf(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
chars = vkprintf(fmt, ap);
chars = __kprintf(fmt, ap);
va_end(ap);
return chars;
@ -154,7 +156,7 @@ tkprintf(const char *fmt, ...)
}
va_start(ap, fmt);
chars = vkprintf(fmt, ap);
chars = __kprintf(fmt, ap);
va_end(ap);
return chars;
@ -173,7 +175,7 @@ nkprintf(const char *fmt, ...)
}
va_start(ap, fmt);
chars = vkprintf(fmt, ap);
chars = __kprintf(fmt, ap);
va_end(ap);
return chars;

View File

@ -30,7 +30,6 @@
#include <types.h>
#include <kern/errmsg.h>
#include <lib.h>
#include <thread.h>
/*
* Like strdup, but calls kmalloc.
@ -61,27 +60,3 @@ strerror(int errcode)
panic("Invalid error code %d\n", errcode);
return NULL;
}
/*
* Helper functions used by testing and problem driver code
* to establish better mixtures of threads.
*/
void
random_yielder(uint32_t max_yield_count)
{
uint32_t i;
for (i = 0; i < random() % max_yield_count; i++) {
thread_yield();
}
}
void
random_spinner(uint32_t max_spin_count)
{
uint32_t i;
volatile int spin;
for (i = 0; i < random() % max_spin_count; i++) {
spin += i;
}
}

27
kern/test/lib.c Normal file
View File

@ -0,0 +1,27 @@
#include <types.h>
#include <thread.h>
#include <test.h>
/*
* Helper functions used by testing and problem driver code
* to establish better mixtures of threads.
*/
void
random_yielder(uint32_t max_yield_count)
{
uint32_t i;
for (i = 0; i < random() % max_yield_count; i++) {
thread_yield();
}
}
void
random_spinner(uint32_t max_spin_count)
{
uint32_t i;
volatile int spin;
for (i = 0; i < random() % max_spin_count; i++) {
spin += i;
}
}

View File

@ -68,7 +68,6 @@
#include <thread.h>
#include <test.h>
#include <synch.h>
#include <synchprobs.h>
/*
* Called by the driver during initialization.

View File

@ -11,7 +11,6 @@
#include <test.h>
#include <current.h>
#include <synch.h>
#include <synchprobs.h>
#define PROBLEMS_MAX_YIELDER 16
#define PROBLEMS_MAX_SPINNER 8192

View File

@ -39,7 +39,6 @@
#include <thread.h>
#include <test.h>
#include <synch.h>
#include <synchprobs.h>
/*
* Called by the driver during initialization.