Work on a test command

This commit is contained in:
Adrien Bourmault 2019-11-25 17:22:54 +01:00
parent ed5482fd1d
commit a4bf874276
3 changed files with 48 additions and 23 deletions

View File

@ -31,10 +31,6 @@
//----------------------------------------------------------------------------//
void ShStartShell(void);
//----------------------------------------------------------------------------//
#define CMDBUFSIZE 256
typedef struct Command_t Command_t;
@ -55,5 +51,9 @@ extern Command_t shcmdtable[];
//----------------------------------------------------------------------------//
void ShStartShell(void);
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable);
#endif

View File

@ -32,6 +32,8 @@
#include <sh/shell.h>
#include <po/shtdwn.h>
static Command_t testcmdtable[];
static inline int ShAtoi(char* str)
{
int res = 0;
@ -182,6 +184,26 @@ error_t CmdHelp(int argc, char **argv, char *cmdline)
return EOK;
}
error_t CmdHelpTest(int argc, char **argv, char *cmdline)
{
uint i, count = 0;
Command_t *cmd;
if (argc == 1) {
KernLog("List of all test built-ins:\n");
for (cmd = testcmdtable; cmd->name != NULL; cmd++, count++) {
KernLog("\t%s", cmd->name);
for (i = strlen(cmd->name)/4; i<3; i++) {
KernLog("\t");
}
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
}
KernLog("End of list; %u commands total\n", count);
}
return EOK;
}
error_t CmdMemMap(int argc, char **argv, char *cmdline)
{
MmPrintMemoryMap();
@ -259,12 +281,9 @@ error_t CmdStarWars(int argc, char **argv, char *cmdline)
error_t CmdTest(int argc, char **argv, char *cmdline)
{
ExecuteCommand(cmdline+5, testcmdtable);
KernLog ("\n");
}
error_t CmdTest(int argc, char **argv, char *cmdline)
{
KernLog("%s\n", &KeFormatCurTime()[13]);
return EOK;
}
@ -314,30 +333,37 @@ error_t CmdVersion(int argc, char **argv, char *cmdline)
//----------------------------------------------------------------------------//
Command_t shcmdtable[] =
static Command_t testcmdtable[] =
{
{ "args", CmdArgs, "Print command line" },
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
{ "help", CmdHelpTest, "Show this message" },
{ "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
{ "pstest", CmdPsTest, "Scheduler test routine" },
{ "rpag", CmdReloadPage, "Reload the pages directory" },
{ "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
{ "timer", CmdTimerTest, "test timer of x ms" },
{ NULL, NULL, NULL }
};
Command_t shcmdtable[] =
{
{ "beep", CmdBeep, "Make a beep" },
{ "cls", CmdClear, "Clears standard output" },
{ "color", CmdColor, "Change shell text color" },
{ "date", CmdDate, "Print date" },
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" },
{ "march", CmdStarWars, "Play the Imperial March" },
{ "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" },
{ "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
{ "pstest", CmdPsTest, "Scheduler test routine" },
{ "quit", CmdQuit, "Alias for 'exit'" },
{ "rpag", CmdReloadPage, "Reload the pages directory" },
{ "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
{ "sleep", CmdSleep, "Sleep x ms" },
{ "testimer", CmdTimerTest, "test timer of x ms" },
{ "time", CmdTime, "Print time" },
{ "test", CmdTest, "Launch the x test" },
{ "ver", CmdVersion, "Version and legal infos" },
{ NULL, NULL, NULL }
};

View File

@ -36,7 +36,7 @@ int shcol = VGA_COLOR_LIGHT_GREY;
static char *argvbuf = 0;
static void ExecuteCommand(char *cmdbuf)
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
{
error_t rc;
Command_t *cmd;
@ -49,7 +49,7 @@ static void ExecuteCommand(char *cmdbuf)
rc = ShCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
for (cmd = shcmdtable; cmd->name != NULL; cmd++) {
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
if (!strcmp(cmd->name, shargv[0])) {
cmd->func(shargc, shargv, cmdbuf);
found = true;
@ -86,7 +86,7 @@ void ShStartShell(void)
if (!(BStdIn->flags & BF_ERR)) {
*bufptr = 0;
bufptr = cmdbuf;
ExecuteCommand(cmdbuf);
ExecuteCommand(cmdbuf, shcmdtable);
memzero(cmdbuf, CMDBUFSIZE);
BFlushBuf(BStdIn);
@ -148,7 +148,7 @@ void ShStartShell(void)
*bufptr = 0;
bufptr = cmdbuf;
ExecuteCommand(cmdbuf);
ExecuteCommand(cmdbuf, shcmdtable);
memzero(cmdbuf, CMDBUFSIZE);
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
@ -161,4 +161,3 @@ void ShStartShell(void)
}
KernLog("[EOI]\n");
}