Parcourir la source

Add shell automated tests

pull/85/head
Virgil Dupras il y a 4 ans
Parent
révision
9ab292a6d5
11 fichiers modifiés avec 101 ajouts et 18 suppressions
  1. +10
    -0
      tools/emul/README.md
  2. +45
    -17
      tools/emul/shell/shell.c
  3. +2
    -1
      tools/tests/Makefile
  4. +1
    -0
      tools/tests/shell/.gitignore
  5. +1
    -0
      tools/tests/shell/cfsin/bar
  6. +1
    -0
      tools/tests/shell/cfsin/foo
  7. +5
    -0
      tools/tests/shell/fls.expected
  8. +1
    -0
      tools/tests/shell/fls.replay
  9. +4
    -0
      tools/tests/shell/print.expected
  10. +1
    -0
      tools/tests/shell/print.replay
  11. +30
    -0
      tools/tests/shell/runtests.sh

+ 10
- 0
tools/emul/README.md Voir le fichier

@@ -25,6 +25,16 @@ We don't try to emulate real hardware to ease the development of device drivers
because so far, I don't see the advantage of emulation versus running code on
the real thing.

By default, the shell initialized itself with a CFS device containing the
contents of `cfsin/` at launch (it's packed on the fly). You can specify an
alternate CFS device file (it has to be packaed already) through the `-f` flag.

By default, the shell runs interactively, but you can also pipe contents through
stdin instead. The contents will be interpreted exactly as if you had typed it
yourself and the result will be spit in stdout (it includes your typed in
contents because the Collapse OS console echoes back every character that is
sent to it.). This feature is useful for automated tests in `tools/tests/shell`.

## zasm

`zasm/zasm` is `apps/zasm` wrapped in an emulator. It is quite central to the


+ 45
- 17
tools/emul/shell/shell.c Voir le fichier

@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include "../emul.h"
#include "shell-bin.h"
@@ -135,12 +136,36 @@ static void iowr_fsaddr(uint8_t val)
}
}

int main()
int main(int argc, char *argv[])
{
FILE *fp = NULL;
while (1) {
int c = getopt(argc, argv, "f:");
if (c < 0) {
break;
}
switch (c) {
case 'f':
fp = fopen(optarg, "r");
if (fp == NULL) {
fprintf(stderr, "Can't open %s\n", optarg);
return 1;
}
break;
default:
fprintf(stderr, "Usage: shell [-f fsdev]\n");
return 1;
}
}
// Setup fs blockdev
FILE *fp = popen("../cfspack/cfspack cfsin", "r");
if (fp == NULL) {
fp = popen("../cfspack/cfspack cfsin", "r");
if (fp == NULL) {
fprintf(stderr, "Can't initialize filesystem. Leaving blank.\n");
}
}
if (fp != NULL) {
printf("Initializing filesystem\n");
fprintf(stderr, "Initializing filesystem\n");
int i = 0;
int c = fgetc(fp);
while (c != EOF) {
@@ -150,19 +175,20 @@ int main()
}
fsdev_size = i;
pclose(fp);
} else {
printf("Can't initialize filesystem. Leaving blank.\n");
}

// Turn echo off: the shell takes care of its own echoing.
bool tty = isatty(fileno(stdin));
struct termios termInfo;
if (tcgetattr(0, &termInfo) == -1) {
printf("Can't setup terminal.\n");
return 1;
if (tty) {
// Turn echo off: the shell takes care of its own echoing.
if (tcgetattr(0, &termInfo) == -1) {
printf("Can't setup terminal.\n");
return 1;
}
termInfo.c_lflag &= ~ECHO;
termInfo.c_lflag &= ~ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);
}
termInfo.c_lflag &= ~ECHO;
termInfo.c_lflag &= ~ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);


Machine *m = emul_init();
@@ -182,10 +208,12 @@ int main()

while (running && emul_step());

printf("Done!\n");
termInfo.c_lflag |= ECHO;
termInfo.c_lflag |= ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);
emul_printdebug();
if (tty) {
printf("Done!\n");
termInfo.c_lflag |= ECHO;
termInfo.c_lflag |= ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);
emul_printdebug();
}
return 0;
}

+ 2
- 1
tools/tests/Makefile Voir le fichier

@@ -2,6 +2,7 @@ EMULDIR = ../emul

.PHONY: run
run:
$(MAKE) -C $(EMULDIR) zasm/zasm runbin/runbin
$(MAKE) -C $(EMULDIR) zasm/zasm runbin/runbin shell/shell
cd unit && ./runtests.sh
cd zasm && ./runtests.sh
cd shell && ./runtests.sh

+ 1
- 0
tools/tests/shell/.gitignore Voir le fichier

@@ -0,0 +1 @@
/test.cfs

+ 1
- 0
tools/tests/shell/cfsin/bar Voir le fichier

@@ -0,0 +1 @@
Hello Bar!

+ 1
- 0
tools/tests/shell/cfsin/foo Voir le fichier

@@ -0,0 +1 @@
Hello Foo!

+ 5
- 0
tools/tests/shell/fls.expected Voir le fichier

@@ -0,0 +1,5 @@
Collapse OS
> fls
bar
foo
>

+ 1
- 0
tools/tests/shell/fls.replay Voir le fichier

@@ -0,0 +1 @@
fls

+ 4
- 0
tools/tests/shell/print.expected Voir le fichier

@@ -0,0 +1,4 @@
Collapse OS
> print 42
42
>

+ 1
- 0
tools/tests/shell/print.replay Voir le fichier

@@ -0,0 +1 @@
print 42

+ 30
- 0
tools/tests/shell/runtests.sh Voir le fichier

@@ -0,0 +1,30 @@
#!/bin/sh -e

EMULDIR=../../emul
SHELL=../../emul/shell/shell

replay() {
fn=$1
replayfn=${fn%.*}.expected
ACTUAL=$("${SHELL}" -f test.cfs < "${fn}" 2> /dev/null)
EXPECTED=$(cat ${replayfn})
if [ "$ACTUAL" = "$EXPECTED" ]; then
echo ok
else
echo different. Whole output:
echo "${ACTUAL}"
exit 1
fi
}

../../cfspack/cfspack cfsin > test.cfs

if [ ! -z $1 ]; then
replay $1
exit 0
fi

for fn in *.replay; do
echo "Replaying ${fn}"
replay "${fn}"
done

Chargement…
Annuler
Enregistrer