mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-24 14:28:06 +11:00
Add shell automated tests
This commit is contained in:
parent
43f4c5200e
commit
9ab292a6d5
@ -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
|
||||
|
@ -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,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
tools/tests/shell/.gitignore
vendored
Normal file
1
tools/tests/shell/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/test.cfs
|
1
tools/tests/shell/cfsin/bar
Normal file
1
tools/tests/shell/cfsin/bar
Normal file
@ -0,0 +1 @@
|
||||
Hello Bar!
|
1
tools/tests/shell/cfsin/foo
Normal file
1
tools/tests/shell/cfsin/foo
Normal file
@ -0,0 +1 @@
|
||||
Hello Foo!
|
5
tools/tests/shell/fls.expected
Normal file
5
tools/tests/shell/fls.expected
Normal file
@ -0,0 +1,5 @@
|
||||
Collapse OS
|
||||
> fls
|
||||
bar
|
||||
foo
|
||||
>
|
1
tools/tests/shell/fls.replay
Normal file
1
tools/tests/shell/fls.replay
Normal file
@ -0,0 +1 @@
|
||||
fls
|
4
tools/tests/shell/print.expected
Normal file
4
tools/tests/shell/print.expected
Normal file
@ -0,0 +1,4 @@
|
||||
Collapse OS
|
||||
> print 42
|
||||
42
|
||||
>
|
1
tools/tests/shell/print.replay
Normal file
1
tools/tests/shell/print.replay
Normal file
@ -0,0 +1 @@
|
||||
print 42
|
30
tools/tests/shell/runtests.sh
Executable file
30
tools/tests/shell/runtests.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user