Skip to content

Commit

Permalink
testing: Add support for C source in runner.do_run_in_out_file_test
Browse files Browse the repository at this point in the history
Honor the source file extension, which means that quite a few C++
sources had to be renamed because they were called `.c`.

Also, increase usage of do_run_in_out_file_test.
  • Loading branch information
sbc100 committed May 1, 2019
1 parent def72b5 commit 2ca790e
Show file tree
Hide file tree
Showing 76 changed files with 86 additions and 243 deletions.
1 change: 1 addition & 0 deletions system/include/libc/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _FEATURES_H

#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE)
#error foo
#define _GNU_SOURCE 1
#endif

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/core/test_atexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
#include <stdio.h>
#include <stdlib.h>

extern "C" {
extern int __cxa_thread_atexit(void (*dtor)(void *), void *obj, void *dso_symbol);
extern int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_symbol);
}

static void cleanA() { printf("A\n"); }
static void cleanB() { printf("B\n"); }
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_bigarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Struct {
char x;
int y;
};
Struct buffy[SIZE];
struct Struct buffy[SIZE];

int main() {
for (int i = 0; i < SIZE; i++) {
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_bitfields.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct bitty {
unsigned z : 1;
};
int main() {
bitty b;
struct bitty b;
printf("*");
for (int i = 0; i <= 1; i++)
for (int j = 0; j <= 1; j++)
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/core/test_constglobalstructs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct IUB {
unsigned int pi;
};

IUB iub[] = {{'a', 0.27, 5}, {'c', 0.15, 4}, {'g', 0.12, 3}, {'t', 0.27, 2}, };
struct IUB iub[] = {{'a', 0.27, 5}, {'c', 0.15, 4}, {'g', 0.12, 3}, {'t', 0.27, 2}, };

const unsigned char faceedgesidx[6][4] = {{4, 5, 8, 10},
{6, 7, 9, 11},
Expand All @@ -22,7 +22,7 @@ const unsigned char faceedgesidx[6][4] = {{4, 5, 8, 10},
{2, 3, 5, 7}, };

int main(int argc, const char *argv[]) {
printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p * 100), iub[2].pi,
printf("*%d,%d,%d,%d*\n", iub[0].c, (int)(iub[1].p * 100), iub[2].pi,
faceedgesidx[3][2]);
return 0;
}
6 changes: 3 additions & 3 deletions tests/core/test_conststructs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ struct IUB {

int main(int argc, const char *argv[]) {
int before = 70;
IUB iub[] = {{'a', 0.3029549426680, 5},
struct IUB iub[] = {{'a', 0.3029549426680, 5},
{'c', 0.15, 4},
{'g', 0.12, 3},
{'t', 0.27, 2}, };
int after = 90;
printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p * 100),
iub[2].pi, int(iub[0].p * 10000), after);
printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, (int)(iub[1].p * 100),
iub[2].pi, (int)(iub[0].p * 10000), after);
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/core/test_double_i64_conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <inttypes.h>
#include <stdio.h>

__attribute((noinline)) bool eq(double d, int64_t i) {
__attribute((noinline)) int eq(double d, int64_t i) {
int64_t i2 = (int64_t)d;
if (i != i2) {
printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/core/test_fakestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct stat {
int x, y;
};
int main() {
stat s;
struct stat s;
s.x = 10;
s.y = 22;
printf("*%d,%d*\n", s.x, s.y);
Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_fcvt.c → tests/core/test_fcvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* found in the LICENSE file.
*/

/* This example borrowed from MSDN documentation */#include <stdlib.h>
/* This example borrowed from MSDN documentation */
#include <stdlib.h>
#include <stdio.h>

int main() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions tests/core/test_linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ struct worker_args {
int value;
struct worker_args* next;
};

int main() {
worker_args a;
worker_args b;
struct worker_args a;
struct worker_args b;
a.value = 60;
a.next = &b;
b.value = 900;
b.next = NULL;
worker_args* c = &a;
struct worker_args* c = &a;
int total = 0;
while (c) {
total += c->value;
c = c->next;
}

// Chunk of em
worker_args chunk[10];
struct worker_args chunk[10];
for (int i = 0; i < 9; i++) {
chunk[i].value = i * 10;
chunk[i].next = &chunk[i + 1];
Expand Down
12 changes: 5 additions & 7 deletions tests/core/test_llvm_used.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#include <stdio.h>
#include <emscripten.h>

extern "C" {
__attribute__((annotate("hello attribute world")))
EMSCRIPTEN_KEEPALIVE void foobar(int x) {
printf("Worked! %d\n", x);
}
__attribute__((annotate("hello attribute world")))
EMSCRIPTEN_KEEPALIVE void foobar(int x) {
printf("Worked! %d\n", x);
}

int main() {
emscripten_run_script("Module['_foobar'](10)");
return 0;
emscripten_run_script("Module['_foobar'](10)");
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/core/test_mod_globalstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct malloc_params {
size_t magic, page_size;
};

malloc_params mparams;
struct malloc_params mparams;

#define SIZE_T_ONE ((size_t)1)
#define page_align(S) \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/core/test_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
int test(int i) {
int x = 10;
int ret = reinterpret_cast<long>(&x); // both for the number, and forces x to not be nativized
int ret = (long)&x; // both for the number, and forces x to not be nativized
if (i > 0) {
if ((i % 2001) != 1500)
return test(i - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

// We should also not blow up the stack with byval arguments
#include <stdio.h>

struct vec {
int x, y, z;
vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
static vec add(vec a, vec b) { return vec(a.x + b.x, a.y + b.y, a.z + b.z); }
};

int main() {
int total = 0;
for (int i = 0; i < 1000; i++) {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tests/core/test_statics.c → tests/core/test_statics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct XYZ {
return iT;
}
};

struct S {
static const XYZ &getIdentity() {
static const XYZ iT(XYZ::getIdentity());
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_stdlibs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ int comparer(const void *a, const void *b) {

int main() {
// timeofday
timeval t;
struct timeval t;
gettimeofday(&t, NULL);
printf("*%d,%d\n", int(t.tv_sec), int(t.tv_usec)); // should not crash
printf("*%d,%d\n", (int)t.tv_sec, (int)t.tv_usec); // should not crash

// atexit
atexit(clean);
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/core/test_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ int main(int argc, char **argv) {
puts(argv[2]);
printf("%d\n", atoi(argv[3]) + 2);
const char *foolingthecompiler = "\rabcd";
printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm -
printf("%lu\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm -
// should not be a 0 (end string)
// then a D!
printf("%s\n", NULL); // Should print '(null)', not the string at address 0,
// which is a real address for us!
printf("null -> %s\n", NULL); // Should print '(null)', not the string at address 0,
// which is a real address for us!
printf("/* a comment */\n"); // Should not break the generated code!
printf("// another\n"); // Should not break the generated code!

Expand All @@ -37,8 +37,8 @@ int main(int argc, char **argv) {
free(strdup_val);

{
char *one = "one 1 ONE !";
char *two = "two 2 TWO ?";
const char *one = "one 1 ONE !";
const char *two = "two 2 TWO ?";
char three[1024];
memset(three, '.', 1024);
three[50] = 0;
Expand All @@ -48,8 +48,8 @@ int main(int argc, char **argv) {
}

{
char *one = "string number one top notch";
char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
const char *one = "string number one top notch";
const char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
char three[1000];
strcpy(three, &one[argc * 2]);
char *four = strcat(three, &two[argc * 3]);
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_strings.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ wowie
too
76
5
(null)
null -> (null)
/* a comment */
// another
test
waka ....e 1 O...wo 2 T................................
cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
2 changes: 1 addition & 1 deletion tests/core/test_strptime_tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

void ReadMonth(const char *month)
{
tm value = {0};
struct tm value = {0};
if(strptime(month, "%b", &value))
{
printf("%s: %d\n", month, value.tm_mon);
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/

#include <stdio.h>

struct S {
int x, y;
};

int main() {
S a, b;
struct S a, b;
a.x = 5;
a.y = 6;
b.x = 101;
b.y = 7009;
S *c, *d;
struct S *c, *d;
c = &a;
c->x *= 2;
c = &b;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/core/test_timeb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <sys/timeb.h>

int main() {
timeb tb;
struct timeb tb;
tb.timezone = 1;
printf("*%d\n", ftime(&tb));
assert(tb.time > 10000);
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/dirent/test_readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ void test_scandir() {
}

int main() {
printf("SIGILL: %s\n", strsignal(SIGILL));
atexit(cleanup);
signal(SIGABRT, cleanup);
setup();
Expand Down
10 changes: 10 additions & 0 deletions tests/dirent/test_readdir.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
success
n: 8
name: tmp
name: proc
name: nocanread
name: home
name: foobar
name: dev
name: ..
name: .
1 change: 1 addition & 0 deletions tests/dirent/test_readdir_empty.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2ca790e

Please sign in to comment.