Add checks to buptest and nprog

nprog now checks if emulator is running and gives a much clearer success
/ fail with a log file for the more verbose output.

Also buptest now won't run if emulator is running.
This commit is contained in:
Andrew Hutchings 2021-06-28 22:16:58 +01:00
parent 208ba3d79d
commit 11f6414342
5 changed files with 108 additions and 4 deletions

View File

@ -98,9 +98,57 @@ unsigned int dump_read_8(unsigned int address) {
return value & 0xff; // ODD , A0=1,LDS
}
int check_emulator() {
DIR* dir;
struct dirent* ent;
char buf[512];
long pid;
char pname[100] = {0,};
char state;
FILE *fp=NULL;
const char *name = "emulator";
if (!(dir = opendir("/proc"))) {
perror("can't open /proc, assuming emulator running");
return 1;
}
while((ent = readdir(dir)) != NULL) {
long lpid = atol(ent->d_name);
if(lpid < 0)
continue;
snprintf(buf, sizeof(buf), "/proc/%ld/stat", lpid);
fp = fopen(buf, "r");
if (fp) {
if ( (fscanf(fp, "%ld (%[^)]) %c", &pid, pname, &state)) != 3 ){
printf("fscanf failed, assuming emulator running\n");
fclose(fp);
closedir(dir);
return 1;
}
if (!strcmp(pname, name)) {
fclose(fp);
closedir(dir);
return 1;
}
fclose(fp);
}
}
closedir(dir);
return 0;
}
int main(int argc, char *argv[]) {
uint32_t test_size = 512 * SIZE_KILO, cur_loop = 0;
if (check_emulator()) {
printf("PiStorm emulator running, please stop this before running buptest\n");
return 1;
}
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2);
srand((unsigned int)f2.tv_nsec);

View File

@ -1 +1,15 @@
sudo openocd -f ./nprog/68new.cfg
if pgrep -x "emulator" > /dev/null
then
echo "PiStorm emulator is running, please stop it first"
exit 1
fi
echo "Flashing..."
sudo openocd -f ./nprog/68new.cfg > nprog_log.txt 2>&1
if [ $? -ne 0 ]
then
echo "Flashing failed, please see nprog_log.txt for details"
exit 1
else
echo "Flashing successful!"
fi

View File

@ -1 +1,15 @@
sudo openocd -f ./nprog/68_240.cfg
if pgrep -x "emulator" > /dev/null
then
echo "PiStorm emulator is running, please stop it first"
exit 1
fi
echo "Flashing..."
sudo openocd -f ./nprog/68_240.cfg > nprog_log.txt 2>&1
if [ $? -ne 0 ]
then
echo "Flashing failed, please see nprog_log.txt for details"
exit 1
else
echo "Flashing successful!"
fi

View File

@ -1 +1,15 @@
sudo openocd -f ./nprog/68_240_experimental.cfg
if pgrep -x "emulator" > /dev/null
then
echo "PiStorm emulator is running, please stop it first"
exit 1
fi
echo "Flashing..."
sudo openocd -f ./nprog/68_240_experimental.cfg > nprog_log.txt 2>&1
if [ $? -ne 0 ]
then
echo "Flashing failed, please see nprog_log.txt for details"
exit 1
else
echo "Flashing successful!"
fi

View File

@ -1 +1,15 @@
sudo openocd -f ./nprog/68new_experimental.cfg
if pgrep -x "emulator" > /dev/null
then
echo "PiStorm emulator is running, please stop it first"
exit 1
fi
echo "Flashing..."
sudo openocd -f ./nprog/68new_experimental.cfg > nprog_log.txt 2>&1
if [ $? -ne 0 ]
then
echo "Flashing failed, please see nprog_log.txt for details"
exit 1
else
echo "Flashing successful!"
fi