/* * Copyright (C) 2006, Intel Corporation * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "../biostest.h" int initialized = 0; pid_t lm_pid; int running=0; static void check_do_init(void) { int myHelloWin; newtComponent myHelloText, myHelloForm; int W,H; if (initialized) return; newtGetScreenSize(&W,&H); myHelloWin = newtOpenWindow(1+(W-55)/2, 1+(H-7)/2, 55, 7, "Configuring LMBench 3"); myHelloForm = newtForm(NULL,NULL,0); myHelloText = newtTextbox(3,3,52,4, 0); newtFormAddComponent(myHelloForm, myHelloText); newtTextboxSetText(myHelloText, "Please wait while LMBench is being configured"); newtDrawForm(myHelloForm); newtRefresh(); system("/usr/share/LFDK/plugins/lmbench_install/configure_test.sh"); newtPopWindow(); initialized = 1; } static void run_lmbench(void) { int myHelloWin; newtComponent myHelloText, myHelloForm; pid_t pid; int W,H; newtGetScreenSize(&W,&H); check_do_init(); myHelloWin = newtOpenWindow(1+(W-50)/2, 1+(H-7)/2, 50, 7, "Running LMBench 3"); myHelloForm = newtForm(NULL,NULL,0); myHelloText = newtTextbox(2,3,47,4, 0); newtFormAddComponent(myHelloForm, myHelloText); newtTextboxSetText(myHelloText, "This can take upto 10 minutes"); newtDrawForm(myHelloForm); newtRefresh(); if (( pid= vfork()) < 0) fprintf(stderr, "fork error\n"); if(pid == 0) { lm_pid = getpid()+1; daemon( 1, 1); execv("/usr/share/LFDK/plugins/lmbench_install/run_test.sh", NULL); } else { if(waitpid(pid, NULL, 0) != pid) fprintf(stderr, "ERR: wait pid\n"); } newtPopWindow(); } static char *get_results(void) { FILE *file; char *buffer=strdup(""); file = popen("/usr/share/LFDK/plugins/lmbench_install/get_results.sh", "r"); if (!file) return buffer; while (!feof(file)) { char line[256]; memset(line, 0, 256); if (fgets(line, 255, file)==NULL) break; buffer = scatprintf(buffer, "%s", line); } fclose(file); return buffer; } void lmbench_execute(void) { int W,H; int win; newtComponent myForm; newtComponent myHelloText; newtComponent myOkButton, myRunButton, myAbortButton; newtComponent myText; newtComponent resu; char *reflow; newtGetScreenSize(&W,&H); win = newtOpenWindow(1,1,W-2,H-2, "LMBench 3 testing"); myForm = newtForm(NULL, NULL, 0); myOkButton = newtButton(2,H-6, "Back"); newtFormAddComponent(myForm, myOkButton); myRunButton = newtButton(11,H-6, "Run test (10 minutes)"); newtFormAddComponent(myForm, myRunButton); myAbortButton = newtButton(48,H-6, "Abort"); newtFormAddComponent(myForm, myAbortButton); myText = newtTextbox(1,1,W-5,H-7, NEWT_FLAG_SCROLL); newtFormAddComponent(myForm, myText); reflow = get_results(); newtTextboxSetText(myText,reflow); free(reflow); while (1) { resu = newtRunForm(myForm); if (resu == myRunButton) { run_lmbench(); running=1; reflow = get_results(); newtTextboxSetText(myText,reflow); free(reflow); } else if(resu == myAbortButton) { int myHelloWin; newtComponent myHelloText, myHelloForm; int W,H; newtGetScreenSize(&W,&H); myHelloWin = newtOpenWindow(1+(W-55)/2, 1+(H-7)/2, 55, 7, "Aborting LMBench 3"); myHelloForm = newtForm(NULL,NULL,0); myHelloText = newtTextbox(3,3,52,4, 0); newtFormAddComponent(myHelloForm, myHelloText); if(running) { killpg(lm_pid, 9); newtTextboxSetText(myHelloText, "Killed"); running=0; } else { newtTextboxSetText(myHelloText, "Already done, nothing to kill"); } newtDrawForm(myHelloForm); newtRefresh(); system("sleep 3"); newtPopWindow(); } else break; } newtPopWindow(); } void run_test(void) { register_interactive_test("lmbench version 3", lmbench_execute); }