Skip to content

Commit

Permalink
Merge pull request #219 from opurdila/small-fixes
Browse files Browse the repository at this point in the history
Small fixes and enhancements
  • Loading branch information
Octavian Purdila authored Aug 31, 2016
2 parents 1e947fb + c14dc91 commit d141b16
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tools/lkl/lib/nt-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void thread_exit(void)
static int thread_join(lkl_thread_t tid)
{
/* TODO: error handling */
WaitForSingleObject(tid, INFINITE);
WaitForSingleObject((void *)tid, INFINITE);
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ static void *tls_get(unsigned int key)

static unsigned long long time_ns(void)
{
struct timeval tv;
struct timespec ts;

gettimeofday(&tv, NULL);
clock_gettime(CLOCK_MONOTONIC, &ts);

return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000ULL;
return 1e9*ts.tv_sec + ts.tv_nsec;
}

static void *timer_alloc(void (*fn)(void *), void *arg)
Expand Down
57 changes: 56 additions & 1 deletion tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,59 @@ int test_getpid(char *str, int len)
return TEST_FAILURE;
}

void check_latency(long (*f)(void), long *min, long *max, long *avg)
{
int i;
unsigned long long start, stop, sum = 0;
static const int count = 1000;
long delta;

*min = 1000000000;
*max = -1;

for (i = 0; i < count; i++) {
start = lkl_host_ops.time();
f();
stop = lkl_host_ops.time();
delta = stop - start;
if (*min > delta)
*min = delta;
if (*max < delta)
*max = delta;
sum += delta;
}
*avg = sum / count;
}

static long native_getpid(void)
{
#ifdef __MINGW32__
GetCurrentProcessId();
#else
getpid();
#endif
return 0;
}

int test_syscall_latency(char *str, int len)
{
long min, max, avg;
int tmp;

check_latency(lkl_sys_getpid, &min, &max, &avg);

tmp = snprintf(str, len, "avg/min/max lkl: %ld/%ld/%ld ",
avg, min, max);
str += tmp;
len -= tmp;

check_latency(native_getpid, &min, &max, &avg);

snprintf(str, len, "native: %ld/%ld/%ld", avg, min, max);

return TEST_SUCCESS;
}

#define access_rights 0721

int test_creat(char *str, int len)
Expand Down Expand Up @@ -676,6 +729,7 @@ static void test_thread(void *data)
fprintf(stderr, "%s: %s\n", __func__, lkl_strerror(ret));
}

lkl_stop_syscall_thread();
}

static int test_syscall_thread(char *str, int len)
Expand Down Expand Up @@ -817,9 +871,10 @@ int main(int argc, char **argv)
if (cla.tap_ifname)
TEST(netdev_add);
#endif /* __MINGW32__ */
lkl_start_kernel(&lkl_host_ops, 16 * 1024 * 1024, "");
lkl_start_kernel(&lkl_host_ops, 16 * 1024 * 1024, "loglevel=8");

TEST(getpid);
TEST(syscall_latency);
TEST(umask);
TEST(creat);
TEST(close);
Expand Down
1 change: 1 addition & 0 deletions tools/lkl/tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ static int g_test_pass = 0;
\
printf("%-20s %s [%s]\n", #name, \
ret == TEST_SUCCESS ? "passed" : "failed", str); \
fflush(stdout); \
}

0 comments on commit d141b16

Please sign in to comment.