Commit df0fc998b8139b916c2b268870b74849ca3f34d7

Authored by aurel32
1 parent bbc0d79c

alpha: add tests

This patch creates tests/alpha directory and adds an "hello world"
program as well as two tests.

Signed-off-by: Tristan Gingold <gingold@adacore.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5216 c046a42c-6fe2-441c-8c8c-71466251a162
tests/alpha/Makefile 0 → 100644
  1 +CROSS=alpha-linux-gnu-
  2 +CC=$(CROSS)gcc
  3 +AS=$(CROSS)as
  4 +
  5 +SIM=../../alpha-linux-user/qemu-alpha
  6 +
  7 +CFLAGS=-O
  8 +LINK=$(CC) -v -o $@ crt.o $< -nostdlib
  9 +
  10 +TESTS=test-cond test-cmov
  11 +
  12 +all: hello-alpha $(TESTS)
  13 +
  14 +hello-alpha: hello-alpha.o crt.o
  15 + $(LINK)
  16 +
  17 +test-cond: test-cond.o crt.o
  18 + $(LINK)
  19 +
  20 +test-cmov.o: test-cond.c
  21 + $(CC) -c $(CFLAGS) -DTEST_CMOV -o $@ $<
  22 +
  23 +test-cmov: test-cmov.o crt.o
  24 + $(LINK)
  25 +
  26 +clean:
  27 + $(RM) *.o *~ hello-alpha $(TESTS)
  28 +
  29 +.PHONY: clean all
... ...
tests/alpha/crt.s 0 → 100644
  1 + .text
  2 +
  3 + .globl _start
  4 + .ent _start,0
  5 +_start:
  6 + .frame $15,0,$15
  7 + br $29,1f
  8 +1: ldgp $29, 0($29)
  9 + .prologue 0
  10 + ldq $27,main($29) !literal!1
  11 + jsr $26,($27)
  12 +
  13 + lda $0,1
  14 + callsys
  15 +
  16 + call_pal 0
  17 + .end _start
  18 +
  19 + .globl write
  20 +write:
  21 + lda $0,4
  22 + callsys
  23 + ret
... ...
tests/alpha/hello-alpha.c 0 → 100644
  1 +int main (void)
  2 +{
  3 + write (1, "hello\n", 6);
  4 + return 0;
  5 +}
... ...
tests/alpha/test-cond.c 0 → 100644
  1 +
  2 +#ifdef TEST_CMOV
  3 +
  4 +#define TEST_COND(N) \
  5 +int test_##N (long a) \
  6 +{ \
  7 + int res = 1; \
  8 + \
  9 + asm ("cmov"#N" %1,$31,%0" \
  10 + : "+r" (res) : "r" (a)); \
  11 + return !res; \
  12 +}
  13 +
  14 +#else
  15 +
  16 +#define TEST_COND(N) \
  17 +int test_##N (long a) \
  18 +{ \
  19 + int res = 1; \
  20 + \
  21 + asm ("b"#N" %1,1f\n\t" \
  22 + "addq $31,$31,%0\n\t" \
  23 + "1: unop\n" \
  24 + : "+r" (res) : "r" (a)); \
  25 + return res; \
  26 +}
  27 +
  28 +#endif
  29 +
  30 +TEST_COND(eq)
  31 +TEST_COND(ne)
  32 +TEST_COND(ge)
  33 +TEST_COND(gt)
  34 +TEST_COND(lbc)
  35 +TEST_COND(lbs)
  36 +TEST_COND(le)
  37 +TEST_COND(lt)
  38 +
  39 +static struct {
  40 + int (*func)(long);
  41 + long v;
  42 + int r;
  43 +} vectors[] =
  44 + {
  45 + {test_eq, 0, 1},
  46 + {test_eq, 1, 0},
  47 +
  48 + {test_ne, 0, 0},
  49 + {test_ne, 1, 1},
  50 +
  51 + {test_ge, 0, 1},
  52 + {test_ge, 1, 1},
  53 + {test_ge, -1, 0},
  54 +
  55 + {test_gt, 0, 0},
  56 + {test_gt, 1, 1},
  57 + {test_gt, -1, 0},
  58 +
  59 + {test_lbc, 0, 1},
  60 + {test_lbc, 1, 0},
  61 + {test_lbc, -1, 0},
  62 +
  63 + {test_lbs, 0, 0},
  64 + {test_lbs, 1, 1},
  65 + {test_lbs, -1, 1},
  66 +
  67 + {test_le, 0, 1},
  68 + {test_le, 1, 0},
  69 + {test_le, -1, 1},
  70 +
  71 + {test_lt, 0, 0},
  72 + {test_lt, 1, 0},
  73 + {test_lt, -1, 1},
  74 + };
  75 +
  76 +int main (void)
  77 +{
  78 + int i;
  79 +
  80 + for (i = 0; i < sizeof (vectors)/sizeof(vectors[0]); i++)
  81 + if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) {
  82 + write(1, "Failed\n", 7);
  83 + return 1;
  84 + }
  85 + write(1, "OK\n", 3);
  86 + return 0;
  87 +}
... ...