int main(void){ srand48(time(NULL)); void *h = createVM(VMEMSIZE, PMEMSIZE, PAGESIZE, TLBSIZE, 0, 0); if (h == NULL){ fprintf(stderr, "createVM failed!\n"); exit(1); } uint i=0,j=0; long sum=0, sum2=0; while(i<MEMSIZE){ j=lrand48()%MEMSIZE; if(i==j){ i++; } writeInt(h, j, j); } i=0; while(i<MEMSIZE){ j=lrand48()%MEMSIZE; int tmp = readInt(h, j); sum += tmp; sum2 += tmp; if(i==j){ i++; } } printf("sum is %lu (should be %lu)\n", sum, sum2); // print stats printf("\n"); printStatistics(h); printf("\n"); return 0; }
static int runRepl() { WrenVM* vm = createVM(NULL); printf("\\\\/\"-\n"); printf(" \\_/ wren v0.0.0\n"); char line[MAX_LINE_LENGTH]; for (;;) { printf("> "); if (!fgets(line, MAX_LINE_LENGTH, stdin)) { printf("\n"); break; } // TODO: Handle failure. wrenInterpret(vm, "Prompt", line); // TODO: Automatically print the result of expressions. } wrenFreeVM(vm); return 0; }
void CLuaVM::reset() { if( _vm ){ lua_close(_vm); } createVM(); }
//lua_State* state CLuaVM::CLuaVM() : _vm(0) { //luabind::set_pcall_callback( onLuaError ); //registerErrorHandlers(); createVM(); luabind::set_pcall_callback( onLuaError ); lua_atpanic (this->getVM(), onLuaPanic); }
CVMIDialog::CVMIDialog(QWidget* parent) : QDialog(parent) // : QDialog (0, Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint|Qt::WindowSystemMenuHint|Qt::WindowCloseButtonHint|Qt::Dialog) { // Select page selectPage = new CVMISelectPage; Q_ASSERT(connect(selectPage, SIGNAL(vmSelected(CVMIRelease)), this, SLOT(showVMCreate(CVMIRelease)))); selectPage->setReady(false); // Create page createPage = new CVMICreatePage; Q_ASSERT(connect(createPage, SIGNAL(back()), this, SLOT(showVMSelect()))); Q_ASSERT(connect(createPage, SIGNAL(createVM(CVMIInstanceConfig)), this, SLOT(showVMInstall(CVMIInstanceConfig)))); // Install page installPage = new CVMIInstallPage; Q_ASSERT(connect(installPage, SIGNAL(done()), this, SLOT(showVMSelect()))); // Config page CVMIConfigPage* configPage = new CVMIConfigPage; Q_ASSERT(connect(configPage, SIGNAL(displayOptionChanged()), selectPage, SLOT(displayOptionChanged()))); Q_ASSERT(connect(configPage, SIGNAL(configChanged()), this, SLOT(verifyConfig()))); // About page CVMIAboutPage* aboutPage = new CVMIAboutPage; // Stacked Widget contentWidget = new QStackedWidget; contentWidget->addWidget (selectPage); contentWidget->addWidget (createPage); contentWidget->addWidget (installPage); // Tabs QTabWidget *tabWidget = new QTabWidget; tabWidget->insertTab(0, contentWidget, tr("Installer")); tabWidget->insertTab(1, configPage, tr("Preferences")); tabWidget->insertTab(2, aboutPage, tr("About")); // Window decoration setWindowTitle(tr("CernVM installation tool")); setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint | Qt::CustomizeWindowHint); // Layout QHBoxLayout *bodyLayout = new QHBoxLayout; bodyLayout->addWidget(tabWidget); setLayout(bodyLayout); // Application icon this->setWindowIcon(QIcon(":images/application_icon.png")); verifyConfig(); }
int main() { puts("Running base interpreter tests"); VM *vm = createVM(); compart *com = createComp(vm); bool ret = 0; /************************ Begin Tests *************************************/ { // PUSH,POP bytecode code[] = { {.code = BC_PUSH, { {.a1 =0} } }, //push local at address 0 {.code = BC_POP, { {.a1 =1} }}, // pop into address 1 {.code = BC_END} // end
int main() { puts("Running interpreter jump tests"); VM *vm = createVM(); compart *com = createComp(vm); bool ret = 0; { // JMP 1 bytecode code[] = { {.code = BC_PUSH, { {.a1 =1} } }, //push local at address 1 {.code = BC_PUSH, { {.a1 =2} } }, //push local at address 2 {.code = BC_JMP, {.a = 2} }, // jump forward, skip next instruction
int main() { puts("Running interpreter tests"); VM *vm = createVM(); compart *com = createComp(vm); bool ret = 0; //Tests { // LS/JMN bytecode code[] = { {.code = BC_CPUSH, { {.a1 =1} } }, //push const at address 1 {.code = BC_CPUSH, { {.a1 =0} } }, //push const at address 0 {.code = BC_CPUSH, { {.a1 =0} } }, //push const at address 0
int main() { puts("Running internal tests"); int ret = 0; { //varTable tests varTable vt; var *vs[6]; varTableCreate(&vt, 6); vs[0] = addVar(&vt,INT_VAR, "foo"); vs[1] = addVar(&vt,IS_GLBL | FLOAT_VAR, "bar"); vs[2] = addVar(&vt, FLOAT_VAR | IS_ARRAY, "foobar"); vs[3] = addVar(&vt, FLOAT_VAR, "baz"); vs[4] = addVar(&vt, FLOAT_VAR, "foo"); vs[5] = addVar(&vt, FLOAT_VAR | IS_ARRAY, "foobar"); assert(vs[2] == vs[5]); for(int i=0;i< 5; i++) for(int j=0; j<5;j++) if(j != i) assert(vs[i] != vs[j]); int16_t ind; //int16_t findVar(const varTable *vt,const char *name) ind = findVar(&vt, "foo"); assert(vs[0] == &(vt.vars[ind])); varTableDestroy(&vt); } { // comparment constant testing //int16_t com_addConst(compart *com, intfloat val); } { //test searchSym // typedef struct // { // int16_t id; // bool isvar;// if this is false then symbol is a native or built in function // bool local; // bool array; // bool isfloat; // }symbolinfo; // used for symbol table search (for compiler) // // /** // * search all symbol tables and return info on a symbol // * // * Post: if symbol doesn't exist returns a symbolinfo with id=-1 // * else returns info on symbol // */ // symbolinfo searchSym(const char *name, compart *com) __attribute__ ((pure)); VM *vm = createVM(); compart *com = createComp(vm); //int16_t com_addConst(compart *com, intfloat val); com_addConst(com,(intfloat)0); destroyComp(com); destroyVM(vm); } return ret; }
int main() { puts("Running API tests"); int ret = 0; VM *vm = createVM(); { int *i = vm_addInt(vm,"foo"); if(i != vm_getInt(vm,"foo")) { ret++; puts("VM get/add Int FAIL"); puts("\tget pulled out dif addr"); } else { puts("VM get/add Int PASS"); } if(i != vm_addInt(vm,"foo")) { ret++; puts("VM addInt FAIL"); puts("\tseems to allow dups"); } else { puts("VM addInt PASS"); } if(vm_addFloat(vm,"foo") != NULL) { ret++; puts("VM addFloat FAIL"); puts("\tseems to allow dups (w/int)"); } else { puts("VM addFloat PASS"); } float *f = vm_addFloat(vm,"bar"); if(f != vm_getFloat(vm,"bar")) { ret++; puts("VM get/add Float FAIL"); puts("\tget pulled out dif addr"); } else { puts("VM get/add Float PASS"); } if(vm_addInt(vm,"bar") != NULL) { ret++; puts("VM addInt FAIL"); puts("\tseems to allow dups (w/float)"); } else { puts("VM addInt PASS"); } } destroyVM(vm); return ret; }
int main(int argc, char *argv[]) { /* * Check that PRUnichar is equal in size to what compiler composes L"" * strings from; otherwise NS_LITERAL_STRING macros won't work correctly * and we will get a meaningless SIGSEGV. This, of course, must be checked * at compile time in xpcom/string/nsTDependentString.h, but XPCOM lacks * compile-time assert macros and I'm not going to add them now. */ if (sizeof(PRUnichar) != sizeof(wchar_t)) { printf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n" "Probably, you forgot the -fshort-wchar compiler option.\n", (unsigned long) sizeof(PRUnichar), (unsigned long) sizeof(wchar_t)); return -1; } nsresult rc; /* * This is the standard XPCOM init procedure. * What we do is just follow the required steps to get an instance * of our main interface, which is IVirtualBox. */ #if defined(XPCOM_GLUE) XPCOMGlueStartup(nsnull); #endif /* * Note that we scope all nsCOMPtr variables in order to have all XPCOM * objects automatically released before we call NS_ShutdownXPCOM at the * end. This is an XPCOM requirement. */ { nsCOMPtr<nsIServiceManager> serviceManager; rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull); if (NS_FAILED(rc)) { printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc); return -1; } #if 0 /* * Register our components. This step is only necessary if this executable * implements XPCOM components itself which is not the case for this * simple example. */ nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager); if (!registrar) { printf("Error: could not query nsIComponentRegistrar interface!\n"); return -1; } registrar->AutoRegister(nsnull); #endif /* * Make sure the main event queue is created. This event queue is * responsible for dispatching incoming XPCOM IPC messages. The main * thread should run this event queue's loop during lengthy non-XPCOM * operations to ensure messages from the VirtualBox server and other * XPCOM IPC clients are processed. This use case doesn't perform such * operations so it doesn't run the event loop. */ nsCOMPtr<nsIEventQueue> eventQ; rc = NS_GetMainEventQ(getter_AddRefs (eventQ)); if (NS_FAILED(rc)) { printf("Error: could not get main event queue! rc=%08X\n", rc); return -1; } /* * Now XPCOM is ready and we can start to do real work. * IVirtualBox is the root interface of VirtualBox and will be * retrieved from the XPCOM component manager. We use the * XPCOM provided smart pointer nsCOMPtr for all objects because * that's very convenient and removes the need deal with reference * counting and freeing. */ nsCOMPtr<nsIComponentManager> manager; rc = NS_GetComponentManager (getter_AddRefs (manager)); if (NS_FAILED(rc)) { printf("Error: could not get component manager! rc=%08X\n", rc); return -1; } nsCOMPtr<IVirtualBox> virtualBox; rc = manager->CreateInstanceByContractID (NS_VIRTUALBOX_CONTRACTID, nsnull, NS_GET_IID(IVirtualBox), getter_AddRefs(virtualBox)); if (NS_FAILED(rc)) { printf("Error, could not instantiate VirtualBox object! rc=0x%x\n", rc); return -1; } printf("VirtualBox object created\n"); //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// listVMs(virtualBox); createVM(virtualBox); //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /* this is enough to free the IVirtualBox instance -- smart pointers rule! */ virtualBox = nsnull; /* * Process events that might have queued up in the XPCOM event * queue. If we don't process them, the server might hang. */ eventQ->ProcessPendingEvents(); } /* * Perform the standard XPCOM shutdown procedure. */ NS_ShutdownXPCOM(nsnull); #if defined(XPCOM_GLUE) XPCOMGlueShutdown(); #endif printf("Done!\n"); return 0; }
/* * Parse command line arguments to find those arguments that * 1) affect the starting of the VM, * 2) can be handled without starting the VM, or * 3) contain quotes * then call createVM(). */ int main(int argc, const char **argv) { Me = strrchr(*argv, '/') + 1; ++argv, --argc; initialHeapSize = heap_default_initial_size; maximumHeapSize = heap_default_maximum_size; /* * Debugging: print out command line arguments. */ if (DEBUG) { printf("RunBootImage.main(): process %d command line arguments\n",argc); for (int j=0; j<argc; j++) { printf("\targv[%d] is \"%s\"\n",j, argv[j]); } } // call processCommandLineArguments(). bool fastBreak = false; // Sets JavaArgc JavaArgs = processCommandLineArguments(argv, argc, &fastBreak); if (fastBreak) { exit(EXIT_STATUS_BOGUS_COMMAND_LINE_ARG); } if (DEBUG) { printf("RunBootImage.main(): after processCommandLineArguments: %d command line arguments\n", JavaArgc); for (int j = 0; j < JavaArgc; j++) { printf("\tJavaArgs[%d] is \"%s\"\n", j, JavaArgs[j]); } } /* Verify heap sizes for sanity. */ if (initialHeapSize == heap_default_initial_size && maximumHeapSize != heap_default_maximum_size && initialHeapSize > maximumHeapSize) { initialHeapSize = maximumHeapSize; } if (maximumHeapSize == heap_default_maximum_size && initialHeapSize != heap_default_initial_size && initialHeapSize > maximumHeapSize) { maximumHeapSize = initialHeapSize; } if (maximumHeapSize < initialHeapSize) { fprintf(SysTraceFile, "%s: maximum heap size %lu MiB is less than initial heap size %lu MiB\n", Me, (unsigned long) maximumHeapSize/(1024*1024), (unsigned long) initialHeapSize/(1024*1024)); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } if (DEBUG){ printf("\nRunBootImage.main(): VM variable settings\n"); printf("initialHeapSize %lu\nmaxHeapSize %lu\n" "bootCodeFileName |%s|\nbootDataFileName |%s|\n" "bootRmapFileName |%s|\n" "lib_verbose %d\n", (unsigned long) initialHeapSize, (unsigned long) maximumHeapSize, bootCodeFilename, bootDataFilename, bootRMapFilename, lib_verbose); } if (!bootCodeFilename) { fprintf(SysTraceFile, "%s: please specify name of boot image code file using \"-X:ic=<filename>\"\n", Me); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } if (!bootDataFilename) { fprintf(SysTraceFile, "%s: please specify name of boot image data file using \"-X:id=<filename>\"\n", Me); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } if (!bootRMapFilename) { fprintf(SysTraceFile, "%s: please specify name of boot image ref map file using \"-X:ir=<filename>\"\n", Me); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } #ifdef __MACH__ // Initialize timer information on OS/X (void) mach_timebase_info(&timebaseInfo); #endif int ret = createVM(0); assert(ret == 1); // must be 1 (error status for this func.) fprintf(SysErrorFile, "%s: Could not create the virtual machine; goodbye\n", Me); exit(EXIT_STATUS_MISC_TROUBLE); }
int main() { puts("Running Compiler Tests"); const int NUM_FILES=12; const char * files[] = { "src/test/base.csl", "src/test/debug.csl", "src/test/decls.csl", "src/test/decls2.csl", "src/test/math.csl", "src/test/functions.csl", "src/test/expressions.csl", "src/test/casting.csl", "src/test/flow.csl", "src/test/mincrash.csl", "src/test/comparison.csl", "src/test/arrays.csl", NULL }; const char *err_files[] = { "src/test/missingDec.csl", "src/test/error.csl", NULL }; VM *veem = createVM(); compart *com[NUM_FILES]; addPrintLibToVm(veem); addDebugLibToVm(veem); for(int i=0;files[i] != NULL;i++) { int ret; printf("File %s: ",files[i]); com[i] = createComp(veem); ret = fileCompile(files[i], com[i]); fflush(stdout); fflush(stderr); if(ret==0){ printf("\tCompile: OK, Run: "); runCubbyhole(com[i], 0); fflush(stdout); fflush(stderr); if(i==0) printf("OK\n"); } else { printf("\tCompile: FAIL with exit code %i\n", ret); } destroyComp(com[i]); } destroyVM(veem); puts("Beginning error testing"); comp_out=fopen(BIT_BUCKET,"w"); VM *evm = createVM(); compart *ecom=NULL; if(evm == NULL) { puts("Error creating VM"); return 1; } for(int i=0;err_files[i] != NULL;i++) { int ret; printf("File %s: ",err_files[i]); ecom = createComp(evm); if(ecom == NULL) { printf("Error creating compartment"); return 1; } ret = fileCompile(err_files[i], ecom); fflush(stdout); fflush(stderr); if(ret==0){ printf("\tFAIL\n"); return 2; } else { printf("\tPASS\n"); } fflush(stdout); fflush(stderr); destroyComp(ecom); ecom = NULL; } destroyVM(evm); fclose(comp_out); return 0; }
/* * Parse command line arguments to find those arguments that * 1) affect the starting of the VM, * 2) can be handled without starting the VM, or * 3) contain quotes * then call createVM(). */ int main(int argc, const char **argv) { Me = strrchr(*argv, '/') + 1; ++argv, --argc; initialHeapSize = heap_default_initial_size; maximumHeapSize = heap_default_maximum_size; #ifdef RVM_WITH_FLEXIBLE_STACK_SIZES const unsigned stack_minimum_size = VM_Constants_STACK_SIZE_MIN; const unsigned stack_default_initial_size = VM_Constants_STACK_SIZE_NORMAL_DEFAULT; const unsigned stack_grow_minimum_increment = VM_Constants_STACK_SIZE_GROW_MIN; const unsigned stack_default_grow_increment = VM_Constants_STACK_SIZE_GROW_DEFAULT; const unsigned stack_default_maximum_size = VM_Constants_STACK_SIZE_MAX_DEFAULT; initialStackSize = stack_default_initial_size; stackGrowIncrement = stack_default_grow_increment; maximumStackSize = stack_default_maximum_size; #endif // RVM_WITH_FLEXIBLE_STACK_SIZES /* * Debugging: print out command line arguments. */ if (DEBUG) { printf("RunBootImage.main(): process %d command line arguments\n",argc); for (int j=0; j<argc; j++) { printf("\targv[%d] is \"%s\"\n",j, argv[j]); } } // call processCommandLineArguments(). bool fastBreak = false; // Sets JavaArgc JavaArgs = processCommandLineArguments(argv, argc, &fastBreak); if (fastBreak) { exit(EXIT_STATUS_BOGUS_COMMAND_LINE_ARG); } if (DEBUG) { printf("RunBootImage.main(): after processCommandLineArguments: %d command line arguments\n", JavaArgc); for (int j = 0; j < JavaArgc; j++) { printf("\tJavaArgs[%d] is \"%s\"\n", j, JavaArgs[j]); } } #ifdef RVM_FOR_LINUX if (rvm_singleVirtualProcessor <= -2) { if (running_Debian()) rvm_singleVirtualProcessor = -1; else rvm_singleVirtualProcessor = 0; } if (rvm_singleVirtualProcessor < 0) // Debian. rvm_singleVirtualProcessor = singleVirtualProcessor_for_Debian(); #else /* Turn it off for all non-Linux systems. We could print a diagnostic * message here, but that seems like too much work to implement. */ if (rvm_singleVirtualProcessor < 0) rvm_singleVirtualProcessor = 0; #endif /* Verify heap sizes for sanity. */ if (initialHeapSize == heap_default_initial_size && maximumHeapSize != heap_default_maximum_size && initialHeapSize > maximumHeapSize) { initialHeapSize = maximumHeapSize; } if (maximumHeapSize == heap_default_maximum_size && initialHeapSize != heap_default_initial_size && initialHeapSize > maximumHeapSize) { maximumHeapSize = initialHeapSize; } if (maximumHeapSize < initialHeapSize) { fprintf(SysTraceFile, "%s: maximum heap size %lu MiB is less than initial heap size %lu MiB\n", Me, (unsigned long) maximumHeapSize/(1024*1024), (unsigned long) initialHeapSize/(1024*1024)); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } #ifdef RVM_WITH_FLEXIBLE_STACK_SIZES /* Verify stack sizes for sanity. */ if (initialStackSize == stack_default_initial_size && maximumStackSize != stack_default_maximum_size && initialStackSize > maximumStackSize) { initialStackSize = maximumStackSize; } if (maximumStackSize == stack_default_maximum_size && initialStackSize != stack_default_initial_size && initialStackSize > maximumStackSize) { maximumStackSize = initialStackSize; } if (maximumStackSize < initialStackSize) { fprintf(SysTraceFile, "%s: maximum stack size %lu KiB is less than initial stack size %lu KiB\n", Me, (unsigned long) maximumStackSize/1024, (unsigned long) initialStackSize/1024); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } if (initialStackSize < stack_minimum_size) { fprintf(SysTraceFile, "%s: initial stack size %lu KiB is less than minimum stack size %lu KiB\n", Me, (unsigned long) initialStackSize/1024, (unsigned long) stack_minimum_size/1024); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } if (stackGrowIncrement < stack_grow_minimum_increment) { fprintf(SysTraceFile, "%s: stack growth increment %lu KiB is less than minimum growth increment %lu KiB\n", Me, (unsigned long) stackGrowIncrement/1024, (unsigned long) stack_grow_minimum_increment/1024); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } #endif // RVM_WITH_FLEXIBLE_STACK_SIZES if (DEBUG){ printf("\nRunBootImage.main(): VM variable settings\n"); printf("initialHeapSize %lu\nmaxHeapSize %lu\n" #ifdef RVM_WITH_FLEXIBLE_STACK_SIZES "initialStackSize %lu\n" "stackGrowIncrement %lu\n" "maxStackSize %lu\n" #endif // RVM_WITH_FLEXIBLE_STACK_SIZES "rvm_singleVirtualProcessor %d\n" "bootFileName |%s|\nlib_verbose %d\n", (unsigned long) initialHeapSize, (unsigned long) maximumHeapSize, #ifdef RVM_WITH_FLEXIBLE_STACK_SIZES (unsigned long) initialStackSize, (unsigned long) stackGrowIncrement, (unsigned long) maximumStackSize, #endif // RVM_WITH_FLEXIBLE_STACK_SIZES rvm_singleVirtualProcessor, bootFilename, lib_verbose); } if (!bootFilename) { #define STRINGIZE(x) #x #ifdef RVM_BOOTIMAGE bootFilename = STRINGIZE(RVM_BOOTIMAGE); #endif } if (!bootFilename) { fprintf(SysTraceFile, "%s: please specify name of boot image file using \"-i<filename>\"\n", Me); return EXIT_STATUS_BOGUS_COMMAND_LINE_ARG; } int ret = createVM(0); assert(ret == 1); // must be 1 (error status for this func.) fprintf(SysErrorFile, "%s: Could not create the virtual machine; goodbye\n", Me); exit(EXIT_STATUS_MISC_TROUBLE); }