userland: move getchar from cpp-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent e611806df9
commit fb3fdaa8a6
3 changed files with 41 additions and 0 deletions

View File

@@ -3785,6 +3785,25 @@ Simulated exit code not 0! Exit code is 1
which we parse in link:run[] and then exit with the correct result ourselves... which we parse in link:run[] and then exit with the correct result ourselves...
==== gem5 syscall emulation mode program stdin
gem5 shows its own stdout to terminal, and does not allow you to type stdin to programs.
Instead, you must pass stdin non-interactively with the through a file with the `--se.py --input` option, e.g.:
....
printf a > f
./run --emulator gem5 --userland userland/c/getchar.c --static -- --input f
....
leads to gem5 output:
....
enter a character: you entered: a
....
Source: link:userland/c/getchar.c[]
==== User mode vs full system benchmark ==== User mode vs full system benchmark
Let's see if user mode runs considerably faster than full system or not. Let's see if user mode runs considerably faster than full system or not.

View File

@@ -75,6 +75,7 @@ path_properties_tree = PrefixTree({
'c': PrefixTree({ 'c': PrefixTree({
'assert_fail.c': PrefixTree(value=PathProperties(exit_status=1)), 'assert_fail.c': PrefixTree(value=PathProperties(exit_status=1)),
'false.c': PrefixTree(value=PathProperties(exit_status=1)), 'false.c': PrefixTree(value=PathProperties(exit_status=1)),
'getchar.c': PrefixTree(value=PathProperties(interactive=True)),
'infinite_loop.c': PrefixTree(value=PathProperties(more_than_1s=True)), 'infinite_loop.c': PrefixTree(value=PathProperties(more_than_1s=True)),
}), }),
'kernel_modules': PrefixTree(value=PathProperties(requires_kernel_modules=True)), 'kernel_modules': PrefixTree(value=PathProperties(requires_kernel_modules=True)),

21
userland/c/getchar.c Normal file
View File

@@ -0,0 +1,21 @@
/* Get on character from stdin, and then print it back out.
*
* Same as getc(stdin).
*
* You have to press enter for the character to go through:
* https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar
*
* Used at:
* https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1/53937376#53937376
*/
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char c;
printf("enter a character: ");
c = getchar();
printf("you entered: %c\n", c);
return EXIT_SUCCESS;
}