int typeCheck(char* path){ struct stat st; //referance: http://stackoverflow.com/questions/24290273/check-if-input-file-is-a-valid-file-in-c if (stat(path, &st) == -1){ if ((errno == ENOENT) && (strcmp(path, "") != 0)){ int fd = open(path, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO); if (fd == -1){ printf(OPEN_ERROR, path, strerror(errno)); return -1; } return writeRandom(fd, path); } else{ printf(STAT_ERROR, path, strerror(errno)); return -1; } } else{ if (!S_ISBLK(st.st_mode)){ if (S_ISLNK(st.st_mode) || (st.st_nlink > 1)){ printf(LINK_ERROR); return -1; } if (st.st_size != (128 * MB)){ int fd = open(path, O_TRUNC | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); return writeRandom(fd, path); } } else{ printf(BLOCK_ERROR, path); return -1; } } }
void comparisonTest(FSConfigPtr& cfg, FileIO* a, FileIO* b) { const int size = 2 * 1024; writeRandom(cfg, a, b, 0, size); if (testing::Test::HasFatalFailure()) return; for (int i = 0; i < 10000; i++) { SCOPED_TRACE(testing::Message() << "Test Loop " << i); int len = 128 + random() % 512; int offset = (len == a->getSize()) ? 0 : random() % (a->getSize() - len); writeRandom(cfg, a, b, offset, len); if (testing::Test::HasFatalFailure()) return; ASSERT_EQ(a->getSize(), b->getSize()); } SCOPED_TRACE("Final Compare"); compare(a, b, 0, a->getSize()); }
// // Performs all the RAM checks on all the regions supplied to the object. // // This variation uses a different seed for each region and performs write // of all regions followed by the verifying read of all regions. It's aim is to // detect chip select problems where two memorys respond to the same address. // // NOTE: The seed cannot be "0". // PERROR CRamCheck::checkChipSelect( ) { PERROR error = errorSuccess; // // Step 1 - Write all the regions // for (int i = 0 ; m_ramRegion[i].end != 0 ; i++) { error = writeRandom( &m_ramRegion[i], (m_ramRegion[i].start & 0xFFFE) + 1, true ); if (FAILED(error)) { break; } } // // Step 2 - Read & verify all the regions // if (SUCCESS(error)) { for (int i = 0 ; m_ramRegion[i].end != 0 ; i++) { error = readVerifyRandom( &m_ramRegion[i], (m_ramRegion[i].start & 0xFFFE) + 1, true ); if (FAILED(error)) { break; } } } return error; }
// // Perform the simple random number write/read RAM check for the supplied region. // PERROR CRamCheck::checkRandom( const RAM_REGION *ramRegion, int seed ) { PERROR error = errorSuccess; // // 2-pass - first pass normal data, second pass invert data. // for (int pass = 0 ; pass < 2 ; pass++) { if (SUCCESS(error)) { error = writeRandom( ramRegion, (int) ramRegion->start + seed, (pass != 0) ); if (FAILED(error)) { break; } } if (SUCCESS(error)) { error = readVerifyRandom( ramRegion, (int) ramRegion->start + seed, (pass != 0) ); if (FAILED(error)) { break; } } } return error; }
void processShell(){ int i=0; ShellCommand * command = NULL; char commandLine[MAX_BUFFER_LINE]; printf("\nvda-command> "); fgets(commandLine, sizeof(commandLine) - 1, stdin); command = createShellCommand(commandLine); if(!strcmp(SHELL_COMMAND_QUIT , trim(command->commandName , getGlobalHeap()))){ setVdaRunningStatus(FALSE); printf("\n"); info(" Finalizando Shell"); return; } else if(!strcmp("posicionCabezal" , trim(command->commandName , getGlobalHeap()))) posicionCabezal(); else if(!strcmp("obtenerSectores" , trim(command->commandName , getGlobalHeap())) && (command->argsCount >0) && (command->argsCount <=5)) obtenerSectores(commandTosectorList (command), command->argsCount); else if(!strcmp("writeRandom" , trim(command->commandName , getGlobalHeap())) && (command->argsCount == 1)) writeRandom(atoi(command->args[0])); else if(!strcmp("showInfo" , trim(command->commandName , getGlobalHeap()))) showInfo(); else if(!strcmp("cacheStatus" , trim(command->commandName , getGlobalHeap()))) cacheStatus(); else if(!strcmp("demoGetSectores" , trim(command->commandName , getGlobalHeap()))) demoGetSectores(); else if(!strcmp("demoPutSectores" , trim(command->commandName , getGlobalHeap()))) demoPutSectores(); else if(!strcmp("demoGetCHS" , trim(command->commandName , getGlobalHeap()))) demoGetCHS(); else if(!strcmp("help" , trim(command->commandName , getGlobalHeap()))) help(); }
MarkovAlgorithm::MarkovAlgorithm() { fillInputText(); buildMaps(); writeRandom(); }