示例#1
0
void VMThread(void *param){
    char LocalVariable;
    
    VMPrint("VMThread Alive\nVMThread testing memory locations\n");
    if((MemoryBase1 < &LocalVariable)&&(&LocalVariable < MemoryBase2)){
        MemoryAllocationSuccess = 1;
    }
    else if((MemoryBase1 > &LocalVariable)&&(&LocalVariable > MemoryBase2)){
        MemoryAllocationSuccess = 1;
    }
    else{
        VMPrint("VMThread stack not allocated from system memory pool\n");
        MemoryAllocationSuccess = 0;
        return;
    }
    VMPrint("VMThread Acquiring Mutex\n");
    if(VM_STATUS_SUCCESS != VMMutexAcquire(TheMutex, VM_TIMEOUT_INFINITE)){
        VMPrint("VMThread failed to acquire mutex\n");
        return;
    }
    VMPrint("VMThread Mutex Acquired\n");
    TheMutexAcquired = 1;
    
    
    while(1);
}
示例#2
0
void VMThreadLow(void *param){
    VMMutexAcquire(MutexMain, VM_TIMEOUT_INFINITE);
    VMPrint("VMThreadLow Alive\n");
    VMMutexAcquire(MutexLow, VM_TIMEOUT_INFINITE);
    VMPrint("VMThreadLow Awake\n");
    VMMutexRelease(MutexMain);
}
示例#3
0
void VMMain(int argc, char *argv[]){
    TVMThreadID VMThreadID;
    TVMThreadState VMState;
    volatile int Index, Val = 0;
    VMPrint("VMMain creating thread.\n");
    VMThreadCreate(VMThread, NULL, 0x100000, VM_THREAD_PRIORITY_NORMAL, &VMThreadID);
    VMPrint("VMMain getting thread state: ");
    VMThreadState(VMThreadID, &VMState);
    switch(VMState){
        case VM_THREAD_STATE_DEAD:       VMPrint("DEAD\n");
                                        break;
        case VM_THREAD_STATE_RUNNING:    VMPrint("RUNNING\n");
                                        break;
        case VM_THREAD_STATE_READY:      VMPrint("READY\n");
                                        break;
        case VM_THREAD_STATE_WAITING:    VMPrint("WAITING\n");
                                        break;
        default:                        break;
    }
    VMPrint("VMMain activating thread.\n");
    VMThreadActivate(VMThreadID);
    VMPrint("VMMain Starting\n");
    for(Index = 0; Index < 1000000000; Index++){
        Val++;
    }
    VMPrint("VMMain Done\nWaiting\n");
    do{
        VMThreadState(VMThreadID, &VMState);
    }while(VM_THREAD_STATE_DEAD != VMState);
    VMPrint("Goodbye\n");
}
示例#4
0
//using namespace std;
void VMMain(int argc, char *argv[]){
    int Index;
    VMPrint("In VMMain:\n");
    for(Index = 0; Index < argc; Index++){
        VMPrint("%d = %s\n", Index, argv[Index]);
    }
    VMPrint("Goodbye\n");    
}
示例#5
0
void VMThread(void *param){
    volatile int Index, Val = 0;
    VMPrint("VMThread Alive\nVMThread Starting\n");
    for(Index = 0; Index < 1000000000; Index++){
        Val++;
    }
    VMPrint("VMThread Done\n");
}
示例#6
0
void VMMain(int argc, char *argv[]){
    TVMThreadID VMThreadIDHigh, VMThreadIDMedium, VMThreadIDLow;
    
    VMPrint("VMMain creating threads.\n");
    VMThreadCreate(VMThreadLow, NULL, 0x100000, VM_THREAD_PRIORITY_LOW, &VMThreadIDLow);
    VMThreadCreate(VMThreadMedium, NULL, 0x100000, VM_THREAD_PRIORITY_NORMAL, &VMThreadIDMedium);
    VMThreadCreate(VMThreadHigh, NULL, 0x100000, VM_THREAD_PRIORITY_HIGH, &VMThreadIDHigh);
    VMPrint("VMMain creating mutexes.\n");
    VMMutexCreate(&MutexMain);
    VMMutexCreate(&MutexLow);
    VMMutexCreate(&MutexMedium);
    VMMutexCreate(&MutexHigh);
    VMPrint("VMMain locking mutexes.\n");
    VMMutexAcquire(MutexLow, VM_TIMEOUT_INFINITE);
    VMMutexAcquire(MutexMedium, VM_TIMEOUT_INFINITE);
    VMMutexAcquire(MutexHigh, VM_TIMEOUT_INFINITE);
    VMPrint("VMMain activating processes.\n");
    VMThreadActivate(VMThreadIDLow);
    VMThreadActivate(VMThreadIDMedium);
    VMThreadActivate(VMThreadIDHigh);
    VMPrint("VMMain releasing mutexes.\n");
    VMMutexRelease(MutexLow);
    VMMutexRelease(MutexMedium);
    VMMutexRelease(MutexHigh);
    VMPrint("VMMain going to sleep.\n");
    VMThreadSleep(1);
    VMPrint("VMMain acquiring main mutex.\n");
    VMMutexAcquire(MutexMain, VM_TIMEOUT_INFINITE);
    VMPrint("VMMain acquired main mutex.\nGoodbye\n");
}
示例#7
0
void VMThread(void *param){
    volatile int *Val = (int *)param;
    int RunTimeTicks;
    TVMTick CurrentTick, EndTick;
    
    VMTickMS(&RunTimeTicks);
    RunTimeTicks = (5000 + RunTimeTicks - 1)/RunTimeTicks;
    VMTickCount(&CurrentTick);
    EndTick = CurrentTick + RunTimeTicks;
    VMPrint("VMThread Alive\nVMThread Starting\n");
    while(EndTick > CurrentTick){
        (*Val)++;
        VMTickCount(&CurrentTick);
    }
    VMPrint("VMThread Done\n");
}
示例#8
0
文件: vm.c 项目: chrisrink10/mscript
ms_Result ms_VMExecuteAndPrint(ms_VM *vm, ms_VMByteCode *bc, ms_Error **err) {
    if ((!vm) || (!bc)) {
        return MS_RESULT_ERROR;
    }

    *err = NULL;
    vm->err = err;

    ms_VMFrame *newf = VMFrameNew(bc);
    if (!newf) {
        return MS_RESULT_ERROR;
    }
    dsarray_append(vm->fstack, newf);

    ms_Result res = VMFrameExecute(vm, newf);
    if (res != MS_RESULT_ERROR) {
        if (!VMStackIsEmpty(vm)) {
            (void) VMPrint(vm);
        }
    }
    return res;
}
示例#9
0
void VMMain(int argc, char *argv[]){
    TVMThreadID VMThreadID1, VMThreadID2;
    TVMThreadState VMState1, VMState2;
    volatile int Val1 = 0, Val2 = 0;
    volatile int LocalVal1, LocalVal2;
    VMPrint("VMMain creating threads.\n");
    VMThreadCreate(VMThread, (void *)&Val1, 0x100000, VM_THREAD_PRIORITY_LOW, &VMThreadID1);
    VMThreadCreate(VMThread, (void *)&Val2, 0x100000, VM_THREAD_PRIORITY_LOW, &VMThreadID2);
    VMPrint("VMMain activating threads.\n");
    VMThreadActivate(VMThreadID1);
    VMThreadActivate(VMThreadID2);
    VMPrint("VMMain Waiting\n");
    do{
        LocalVal1 = Val1; 
        LocalVal2 = Val2;
        VMThreadState(VMThreadID1, &VMState1);
        VMThreadState(VMThreadID2, &VMState2);
        VMPrint("%d %d\n", LocalVal1, LocalVal2);
        VMThreadSleep(2);
    }while((VM_THREAD_STATE_DEAD != VMState1)||(VM_THREAD_STATE_DEAD != VMState2));
    VMPrint("VMMain Done\n");
    VMPrint("Goodbye\n");
}
示例#10
0
void VMThreadHigh(void *param){
    VMPrint("VMThreadHigh Alive\n");
    VMMutexAcquire(MutexHigh, VM_TIMEOUT_INFINITE);
    VMPrint("VMThreadHigh Awake\n");
}
示例#11
0
void VMThreadMedium(void *param){
    VMPrint("VMThreadMedium Alive\n");
    VMMutexAcquire(MutexMedium, VM_TIMEOUT_INFINITE);
    VMPrint("VMThreadMedium Awake\n");
}
示例#12
0
void VMMain(int argc, char *argv[]){
    int FileDescriptor, Length, Offset;
    char Buffer[1024];

    VMPrint("VMMain opening longtest.txt\n");    
    VMFileOpen("longtest.txt", O_CREAT | O_TRUNC | O_RDWR, 0644, &FileDescriptor);
    VMPrint("VMMain VMFileOpen returned %d\n", FileDescriptor);
    
    
    Offset = ((int)'~' - (int)' ') + 1;
    for(Length = 0; Length < sizeof(Buffer); Length++){
        Buffer[Length] = ' ' + (Length % Offset);
    }
    VMPrint("VMMain writing file\n");
    Length = sizeof(Buffer);
    VMFileWrite(FileDescriptor,Buffer,&Length);
    VMPrint("VMMain VMFileWrite returned %d\n", Length);
    VMPrint("VMMain seeking file\n");
    VMFileSeek(FileDescriptor, 448, 0, &Offset);    
    VMPrint("VMMain VMFileSeek offset at %d\n",Offset);
    
    VMPrint("VMMain reading file\n");
    Length = 128;
    VMFileRead(FileDescriptor,Buffer,&Length);
    VMPrint("VMMain VMFileRead returned %d\n", Length);
    if(0 <= Length){
        Buffer[Length] = '\0';
        VMPrint("VMMain read in \"%s\"\n", Buffer);
    }
    VMPrint("VMMain closing file\n");
    VMFileClose(FileDescriptor);
    VMPrint("Goodbye\n");    
}
示例#13
0
文件: sleep.c 项目: 8BitBeat/ECS-150
void VMMain(int argc, char *argv[]){
    VMPrint("Going to sleep for 10 ticks\n");
    VMThreadSleep(10);
    VMPrint("Awake\nGoodbye\n");
}
示例#14
0
void VMMain(int argc, char *argv[]){
    TVMThreadID OtherThreadID, ThisThreadID, BadThreadID, MutexOwner;
    TVMThreadState VMState;
    TVMMutexID BadMutexID;
    TVMMemoryPoolID MemoryPool1;
    TVMMemorySize SystemPoolSize;
    TVMTick CurrentTick, LastTick;
    char *LocalAllocation;
    int MSPerTick;
    
    
    
    VMPrint("VMMain testing VMMemoryPoolQuery.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolQuery(VM_MEMORY_POOL_ID_INVALID, &SystemPoolSize)){
        VMPrint("VMMemoryPoolQuery doesn't handle bad memoryid.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolQuery(VM_MEMORY_POOL_ID_SYSTEM, NULL)){
        VMPrint("VMMemoryPoolQuery doesn't handle NULL bytesleft.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolQuery(VM_MEMORY_POOL_ID_SYSTEM, &SystemPoolSize)){
        VMPrint("VMMemoryPoolQuery doesn't return success with valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMMemoryPoolQuery appears OK.\n");
    VMPrint("VMMain testing VMMemoryPoolAllocate.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_SYSTEM, 0, (void **)&MemoryBase1)){
        VMPrint("VMMemoryPoolAllocate doesn't handle zero size.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_SYSTEM, 64, NULL)){
        VMPrint("VMMemoryPoolAllocate doesn't handle NULL pointer.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_INVALID, 64, (void **)&MemoryBase1)){
        VMPrint("VMMemoryPoolAllocate doesn't handle bad memoryid.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INSUFFICIENT_RESOURCES  != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_SYSTEM, SystemPoolSize + 256, (void **)&MemoryBase1)){
        VMPrint("VMMemoryPoolAllocate doesn't handle insufficient resources.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_SYSTEM, 64, (void **)&MemoryBase1)){
        VMPrint("VMMemoryPoolAllocate doesn't return success with valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMMemoryPoolAllocate appears OK.\n");
    VMPrint("VMMain testing VMThreadCreate.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMThreadCreate(NULL, NULL, 0x100000, VM_THREAD_PRIORITY_NORMAL, &OtherThreadID)){
        VMPrint("VMThreadCreate doesn't handle NULL entry.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMThreadCreate(VMThread, NULL, 0x100000, VM_THREAD_PRIORITY_NORMAL, NULL)){
        VMPrint("VMThreadCreate doesn't handle NULL tid.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMThreadCreate(VMThread, NULL, 0x100000, VM_THREAD_PRIORITY_NORMAL, &OtherThreadID)){
        VMPrint("VMThreadCreate doesn't return success with valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMThreadCreate appears OK.\n");
    if(VM_STATUS_SUCCESS != VMMemoryPoolAllocate(VM_MEMORY_POOL_ID_SYSTEM, 64, (void **)&MemoryBase2)){
        VMPrint("VMMemoryPoolAllocate doesn't return success with valid inputs.\n");    
        return;
    }
    
    VMPrint("VMMain testing VMMemoryPoolCreate.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolCreate(NULL, 64, &MemoryPool1)){
        VMPrint("VMMemoryPoolCreate doesn't handle NULL base.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolCreate((void *)MemoryBase1, 0, &MemoryPool1)){
        VMPrint("VMMemoryPoolCreate doesn't handle zero size.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolCreate((void *)MemoryBase1, 64, NULL)){
        VMPrint("VMMemoryPoolCreate doesn't handle NULL memoryid.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolCreate((void *)MemoryBase1, 64, &MemoryPool1)){
        VMPrint("VMMemoryPoolCreate doesn't return success with valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMMemoryPoolCreate appears OK.\n");
    if(VM_STATUS_SUCCESS != VMMemoryPoolAllocate(MemoryPool1, 32, (void **)&LocalAllocation)){
        VMPrint("VMMemoryPoolAllocate doesn't return success with valid inputs.\n");    
        return;
    }
    if((LocalAllocation != MemoryBase1)&&(LocalAllocation != (MemoryBase1 + 32))){
        VMPrint("VMMemoryPoolAllocate allocated from the wrong pool.\n");    
        return;        
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolQuery(MemoryPool1, &SystemPoolSize)){
        VMPrint("VMMemoryPoolQuery doesn't return success with valid inputs.\n");    
        return;
    }
    if(0 != SystemPoolSize){
        VMPrint("VMMemoryPoolQuery doesn't keep track of actual available memory.\n");    
        return;        
    }
    VMPrint("VMMain testing VMMemoryPoolDeallocate.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolDeallocate(MemoryPool1, NULL)){
        VMPrint("VMMemoryPoolDeallocate doesn't handle NULL base.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolDeallocate(MemoryPool1, LocalAllocation + 1)){
        VMPrint("VMMemoryPoolDeallocate doesn't handle invalid pointer.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolDeallocate(VM_MEMORY_POOL_ID_INVALID, LocalAllocation)){
        VMPrint("VMMemoryPoolDeallocate doesn't handle NULL memoryid.\n");    
        return;
    }
    VMPrint("VMMain VMMemoryPoolDeallocate appears OK.\n");
    VMPrint("VMMain testing VMMemoryPoolDelete.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolDelete(VM_MEMORY_POOL_ID_INVALID)){
        VMPrint("VMMemoryPoolDelete doesn't handle bad memoryid.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_STATE != VMMemoryPoolDelete(MemoryPool1)){
        VMPrint("VMMemoryPoolDelete doesn't handle allocated memory pools.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolDeallocate(MemoryPool1, LocalAllocation)){
        VMPrint("VMMemoryPoolDeallocate doesn't handle valid inputs.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMemoryPoolDelete(MemoryPool1)){
        VMPrint("VMMemoryPoolDelete doesn't handle valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMMemoryPoolDelete appears OK.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolAllocate(MemoryPool1, 32, (void **)&LocalAllocation)){
        VMPrint("VMMemoryPoolAllocate doesn't handle bad memoryid.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMemoryPoolQuery(MemoryPool1, &SystemPoolSize)){
        VMPrint("VMMemoryPoolQuery doesn't handle bad memoryid.\n");    
        return;
    }
    VMPrint("VMMain testing VMThreadID.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMThreadID(NULL)){
        VMPrint("VMThreadID doesn't handle NULL threadref.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMThreadID(&ThisThreadID)){
        VMPrint("VMThreadID doesn't handle valid threadref.\n");    
        return;
    }
    BadThreadID = (OtherThreadID > ThisThreadID ? OtherThreadID : ThisThreadID) + 16;
    VMPrint("VMMain VMThreadID appears OK.\n");
    VMPrint("VMMain testing VMThreadState.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMThreadState(OtherThreadID, NULL)){
        VMPrint("VMThreadState doesn't handle NULL state.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_ID != VMThreadState(BadThreadID, &VMState)){
        VMPrint("VMThreadState doesn't handle bad thread.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMThreadState(OtherThreadID, &VMState)){
        VMPrint("VMThreadState doesn't handle valid inputs.\n");    
        return;
    }
    if(VM_THREAD_STATE_DEAD != VMState){
        VMPrint("VMThreadState returned the wrong value for state.\n");    
        return;        
    }
    VMPrint("VMMain VMThreadState appears OK.\n");
    VMPrint("VMMain testing VMTickMS.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMTickMS(NULL)){
        VMPrint("VMTickMS doesn't handle NULL ticksmsref.\n");    
        return;
    }
    MSPerTick = 100000;
    if(VM_STATUS_SUCCESS != VMTickMS(&MSPerTick)){
        VMPrint("VMTickMS doesn't handle valid inputs.\n");    
        return;
    }
    if((1 > MSPerTick)||(500 <= MSPerTick)){
        VMPrint("VMTickMS doesn't return proper value for tickmsref.\n");    
        return;        
    }
    VMPrint("VMMain VMTickMS appears OK.\n");
    VMPrint("VMMain testing VMTickCount.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMTickCount(NULL)){
        VMPrint("VMTickCount doesn't handle NULL tickref.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMTickCount(&CurrentTick)){
        VMPrint("VMTickCount doesn't handle valid inputs.\n");    
        return;
    }
    VMPrint("VMMain VMTickCount appears OK.\n");
    VMPrint("VMMain testing VMThreadTerminate.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMThreadTerminate(BadThreadID)){
        VMPrint("VMThreadTerminate doesn't handle bad thead.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_STATE != VMThreadTerminate(OtherThreadID)){
        VMPrint("VMThreadTerminate doesn't handle dead thead.\n");    
        return;
    }
    VMPrint("VMMain VMThreadTerminate appears OK.\n");
    VMPrint("VMMain testing VMMutexCreate.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMutexCreate(NULL)){
        VMPrint("VMMutexCreate doesn't handle NULL mutexref.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMutexCreate(&TheMutex)){
        VMPrint("VMMutexCreate doesn't handle valid inputs.\n");    
        return;
    }
    BadMutexID = TheMutex + 16;
    VMPrint("VMMain VMMutexCreate appears OK.\n");
    VMPrint("VMMain testing VMMutexQuery.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMMutexQuery(TheMutex, NULL)){
        VMPrint("VMMutexQuery doesn't handle NULL ownerref.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_ID != VMMutexQuery(BadMutexID, &MutexOwner)){
        VMPrint("VMMutexQuery doesn't handle bad mutex.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMutexQuery(TheMutex, &MutexOwner)){
        VMPrint("VMMutexQuery doesn't handle valid inputs.\n");    
        return;
    }
    if(VM_THREAD_ID_INVALID != MutexOwner){
        VMPrint("VMMutexQuery doesn't correct value for owner.\n");    
        return;        
    }
    VMPrint("VMMain VMMutexQuery appears OK.\n");
    VMPrint("VMMain testing VMThreadSleep.\n");
    if(VM_STATUS_ERROR_INVALID_PARAMETER != VMThreadSleep(VM_TIMEOUT_INFINITE)){
        VMPrint("VMThreadSleep doesn't handle VM_TIMEOUT_INFINITE.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMThreadSleep(VM_TIMEOUT_IMMEDIATE)){
        VMPrint("VMThreadSleep doesn't handle VM_TIMEOUT_IMMEDIATE.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    do{
        LastTick = CurrentTick;
        VMTickCount(&CurrentTick);
    }while(LastTick == CurrentTick);
    if(VM_STATUS_SUCCESS != VMThreadSleep(10)){
        VMPrint("VMThreadSleep doesn't handle valid input.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    if(CurrentTick < LastTick + 10){
        VMPrint("VMThreadSleep doesn't appear to sleep long enough.\n");    
        return;
    }
    VMPrint("VMMain VMThreadSleep appears OK.\n");
    VMPrint("VMMain testing VMThreadActivate.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMThreadActivate(BadThreadID)){
        VMPrint("VMThreadActivate doesn't handle bad thead.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    do{
        LastTick = CurrentTick;
        VMTickCount(&CurrentTick);
    }while(LastTick == CurrentTick);
    LastTick = CurrentTick;
    if(VM_STATUS_SUCCESS != VMThreadActivate(OtherThreadID)){
        VMPrint("VMThreadActivate doesn't handle valid inputs.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    if(CurrentTick != LastTick){
        VMPrint("VMThreadActivate doesn't schedule properly.\n");    
        return;
    }
    VMPrint("VMMain VMThreadActivate appears OK.\n");
    while(-1 == MemoryAllocationSuccess);
    if(0 == MemoryAllocationSuccess){
        VMPrint("VMMain stacks not allocated from system memory pool\n");  
        return;
    }
    while(!TheMutexAcquired);
    VMPrint("VMMain VMThread appears to have Acquired Mutex.\n");
    
    VMMutexQuery(TheMutex, &MutexOwner);
    if(MutexOwner != OtherThreadID){
        VMPrint("VMMutexQuery returned wrong owner of mutex.\n");    
        return;
    }
    
    VMPrint("VMMain testing VMMutexAcquire.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMMutexAcquire(BadMutexID, VM_TIMEOUT_INFINITE)){
        VMPrint("VMMutexAcquire doesn't handle bad mutex.\n");    
        return;
    }
    if(VM_STATUS_FAILURE != VMMutexAcquire(TheMutex, VM_TIMEOUT_IMMEDIATE)){
        VMPrint("VMMutexAcquire doesn't handle VM_TIMEOUT_IMMEDIATE.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    do{
        LastTick = CurrentTick;
        VMTickCount(&CurrentTick);
    }while(LastTick == CurrentTick);
    if(CurrentTick != LastTick + 2){
        VMPrint("Scheduler preemption not handled properly.\n");    
        return;
    }
    LastTick = CurrentTick;
    if(VM_STATUS_FAILURE != VMMutexAcquire(TheMutex, 10)){
        VMPrint("VMMutexAcquire doesn't handle timeout properly.\n");    
        return;
    }
    VMTickCount(&CurrentTick);
    if(CurrentTick < LastTick + 10){
        VMPrint("VMMutexAcquire doesn't handle timeout properly, woke too soon.\n");    
        return;
    }
    VMPrint("VMMain VMMutexAcquire appears OK.\n");
    VMPrint("VMMain testing VMThreadDelete.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMThreadDelete(BadThreadID)){
        VMPrint("VMThreadDelete doesn't handle bad thead.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_STATE != VMThreadDelete(OtherThreadID)){
        VMPrint("VMThreadDelete doesn't handle non-dead thead.\n");    
        return;
    }
    VMPrint("VMMain VMThreadDelete appears OK.\n");
    VMPrint("VMMain testing VMMutexDelete.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMMutexDelete(BadMutexID)){
        VMPrint("VMMutexDelete doesn't handle bad thead.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_STATE != VMMutexDelete(TheMutex)){
        VMPrint("VMMutexDelete doesn't handle held mutexes.\n");    
        return;
    }
    VMPrint("VMMain VMMutexDelete appears OK.\n");
    VMPrint("VMMain testing VMMutexRelease.\n");
    if(VM_STATUS_ERROR_INVALID_ID != VMMutexRelease(BadMutexID)){
        VMPrint("VMMutexRelease doesn't handle bad thead.\n");    
        return;
    }
    if(VM_STATUS_ERROR_INVALID_STATE != VMMutexRelease(TheMutex)){
        VMPrint("VMMutexRelease doesn't handle held mutexes.\n");    
        return;
    }
    VMPrint("VMMain VMMutexRelease appears OK.\n");
    VMPrint("VMMain terminating VMThread.\n");
    if(VM_STATUS_SUCCESS != VMThreadTerminate(OtherThreadID)){
        VMPrint("VMThreadTerminate doesn't handle valid termination.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMThreadState(OtherThreadID, &VMState)){
        VMPrint("VMThreadState doesn't handle valid inputs.\n");    
        return;
    }
    if(VM_THREAD_STATE_DEAD != VMState){
        VMPrint("VMThreadState returned the wrong value for state.\n");    
        return;        
    }
    VMPrint("VMMain VMThreadTerminate appears OK.\n");
    VMPrint("VMMain testing VMMutexAcquire\n");
    if(VM_STATUS_SUCCESS != VMMutexAcquire(TheMutex, VM_TIMEOUT_IMMEDIATE)){
        VMPrint("VMMutexAcquire doesn't handle terminated owners.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMutexQuery(TheMutex, &MutexOwner)){
        VMPrint("VMMutexQuery doesn't handle valid inputs.\n");    
        return;
    }
    if(MutexOwner != ThisThreadID){
        VMPrint("VMMutexQuery returned wrong owner of mutex.\n");    
        return;
    }
    VMPrint("VMMain VMMutexAcquire appears OK.\n");
    VMPrint("VMMain testing VMThreadDelete.\n");
    if(VM_STATUS_SUCCESS != VMThreadDelete(OtherThreadID)){
        VMPrint("VMThreadDelete doesn't handle dead thead.\n");    
        return;
    }
    VMPrint("VMMain VMThreadDelete appears OK.\n");
    
    VMPrint("VMMain testing VMMutexRelease.\n");
    if(VM_STATUS_SUCCESS != VMMutexRelease(TheMutex)){
        VMPrint("VMMutexRelease doesn't handle held mutexes.\n");    
        return;
    }
    if(VM_STATUS_SUCCESS != VMMutexQuery(TheMutex, &MutexOwner)){
        VMPrint("VMMutexQuery doesn't handle valid inputs.\n");    
        return;
    }
    if(VM_THREAD_ID_INVALID != MutexOwner){
        VMPrint("VMMutexQuery doesn't correct value for owner.\n");    
        return;        
    }
    VMPrint("VMMain VMMutexRelease appears OK.\n");
    VMPrint("VMMain testing VMMutexDelete.\n");
    if(VM_STATUS_SUCCESS != VMMutexDelete(TheMutex)){
        VMPrint("VMMutexDelete doesn't handle held mutexes.\n");    
        return;
    }
    VMPrint("VMMain VMMutexDelete appears OK.\n");
    
    VMPrint("VMMain everything appears fine.\nGoodbye\n");
    
}
示例#15
0
文件: vm.c 项目: chrisrink10/mscript
static ms_Result VMFrameExecute(ms_VM *vm, ms_VMFrame *f) {
    assert(vm);
    assert(f);

    ms_VMByteCode *bc = f->code;
    for (f->ip = 0; f->ip < f->code->nops; ) {
        size_t inc = 0;
        ms_VMOpCodeType code = ms_VMOpCodeGetCode(bc->code[f->ip]);
        int arg = ms_VMOpCodeGetArg(bc->code[f->ip]);
        switch (code) {
            case OPC_PRINT:
                inc = VMPrint(vm);
                break;
            case OPC_PUSH:
                inc = VMPush(vm, arg);
                break;
            case OPC_POP:
                inc = VMPop(vm);
                break;
            case OPC_SWAP:
                inc = VMSwap(vm);
                break;
            case OPC_DUP:
                inc = VMDup(vm);
                break;
            case OPC_ADD:
                inc = VMDoBinaryOp(vm, "__add__");
                break;
            case OPC_SUBTRACT:
                inc = VMDoBinaryOp(vm, "__sub__");
                break;
            case OPC_MULTIPLY:
                inc = VMDoBinaryOp(vm, "__mult__");
                break;
            case OPC_DIVIDE:
                inc = VMDoBinaryOp(vm, "__div__");
                break;
            case OPC_IDIVIDE:
                inc = VMDoBinaryOp(vm, "__idiv__");
                break;
            case OPC_MODULO:
                inc = VMDoBinaryOp(vm, "__mod__");
                break;
            case OPC_EXPONENTIATE:
                inc = VMDoBinaryOp(vm, "__exp__");
                break;
            case OPC_NEGATE:
                inc = VMDoUnaryOp(vm, "__neg__");
                break;
            case OPC_SHIFT_LEFT:
                inc = VMDoBinaryOp(vm, "__lshift__");
                break;
            case OPC_SHIFT_RIGHT:
                inc = VMDoBinaryOp(vm, "__rshift__");
                break;
            case OPC_BITWISE_AND:
                inc = VMDoBinaryOp(vm, "__band__");
                break;
            case OPC_BITWISE_XOR:
                inc = VMDoBinaryOp(vm, "__bxor__");
                break;
            case OPC_BITWISE_OR:
                inc = VMDoBinaryOp(vm, "__bor__");
                break;
            case OPC_BITWISE_NOT:
                inc = VMDoUnaryOp(vm, "__bnot__");
                break;
            case OPC_LE:
                inc = VMDoBinaryOp(vm, "__le__");
                break;
            case OPC_LT:
                inc = VMDoBinaryOp(vm, "__lt__");
                break;
            case OPC_GE:
                inc = VMDoBinaryOp(vm, "__ge__");
                break;
            case OPC_GT:
                inc = VMDoBinaryOp(vm, "__gt__");
                break;
            case OPC_EQ:
                inc = VMDoBinaryOp(vm, "__eq__");
                break;
            case OPC_NOT_EQ:
                inc = VMDoBinaryOp(vm, "__ne__");
                break;
            case OPC_NOT:
                inc = VMDoUnaryOp(vm, "__not__");
                break;
            case OPC_AND:
                inc = VMDoBinaryOp(vm, "__and__");
                break;
            case OPC_OR:
                inc = VMDoBinaryOp(vm, "__or__");
                break;
            case OPC_CALL:
                inc = VMCallFunction(vm);
                break;
            case OPC_CALL_BUILTIN:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_PUSH_BLOCK:
                inc = VMPushBlock(vm);
                break;
            case OPC_POP_BLOCK:
                inc = VMPopBlock(vm);
                break;
            case OPC_RETURN:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_GET_ATTR:
                inc = VMDoBinaryOp(vm, "__getattr__");
                break;
            case OPC_SET_ATTR:
                inc = VMDoBinaryOp(vm, "__setattr__");
                break;
            case OPC_DEL_ATTR:
                inc = VMDoBinaryOp(vm, "__delattr__");
                break;
            case OPC_GET_GLO:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_SET_GLO:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_DEL_GLO:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_GET_NAME:
                inc = VMLoadName(vm, arg);
                break;
            case OPC_NEW_NAME:
                inc = VMNewName(vm, arg);
                break;
            case OPC_SET_NAME:
                inc = VMSetName(vm, arg);
                break;
            case OPC_DEL_NAME:
                inc = VMDelName(vm, arg);
                break;
            case OPC_MAKE_LIST:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_MAKE_OBJ:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_NEXT:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_IMPORT:
                ms_VMErrorSet(vm, ERR_NOT_IMPLEMENTED);
                inc = 0;
                break;
            case OPC_JUMP_IF_FALSE: {
                size_t dest;
                if (VMJumpIfFalse(vm, arg, f->ip, &dest)) {
                    f->ip = dest;
                    continue;
                }
                return MS_RESULT_ERROR;
            }
            case OPC_GOTO:              /* fall through */
            case OPC_BREAK:             /* fall through */
            case OPC_CONTINUE:
                f->ip = (size_t)arg;
                continue;
        }
        if (inc == 0) { return MS_RESULT_ERROR; }
        f->ip += inc;
    }

    return MS_RESULT_SUCCESS;
}
示例#16
0
文件: shell.c 项目: 8BitBeat/ECS-150
void VMMain(int argc, char *argv[]){
    int DirDescriptor, FileDescriptor, Length;
    char LineBuffer[1024];
    char DirectoryName[VM_FILE_SYSTEM_MAX_PATH];
    SVMDirectoryEntry DirectoryEntry;
    int CharactersIn = 0;
    int Mil, Kil, One;
    
    while(1){
        VMDirectoryCurrent(DirectoryName);
        VMPrint("%s> ",DirectoryName);
        CharactersIn = 0;
        while(1){
            Length = 1;
            VMFileRead(0, LineBuffer + CharactersIn, &Length);
            if('\n' == LineBuffer[CharactersIn]){
                LineBuffer[CharactersIn] = '\0';
                break;
            }
            if((0 == CharactersIn)&&(' ' == LineBuffer[CharactersIn])){
                continue;
            }
            CharactersIn++;
        }
        
        while(0 < CharactersIn){
            CharactersIn--;
            if(' ' != LineBuffer[CharactersIn]){
                CharactersIn++;
                break;
            }
            LineBuffer[CharactersIn] = '\0';
        }
        if(StringMatch(LineBuffer,"exit")){
            break;
        }
        else if(StringMatch(LineBuffer,"ls")){
            
            if(VM_STATUS_SUCCESS == VMDirectoryOpen(DirectoryName, &DirDescriptor)){
                VMPrint("   DATE   |  TIME  | TYPE |    SIZE   |    SFN      |  LFN\n");
                while(VM_STATUS_SUCCESS == VMDirectoryRead(DirDescriptor, &DirectoryEntry)){
                    VMPrint("%04d/%02d/%02d %02d:%02d %s ",DirectoryEntry.DModify.DYear, DirectoryEntry.DModify.DMonth, DirectoryEntry.DModify.DDay, (DirectoryEntry.DModify.DHour % 12) ? (DirectoryEntry.DModify.DHour % 12) : 12 , DirectoryEntry.DModify.DMinute, DirectoryEntry.DModify.DHour >= 12 ? "PM" : "AM");
                    VMPrint("%s ", DirectoryEntry.DAttributes & VM_FILE_SYSTEM_ATTR_DIRECTORY ? "<DIR> " : "<FILE>");
                    Mil = DirectoryEntry.DSize / 1000000;
                    Kil = (DirectoryEntry.DSize / 1000) % 1000;
                    One = DirectoryEntry.DSize % 1000;
                    if(Mil){
                        VMPrint("%3d,%03d,%03d ",Mil, Kil, One);   
                    }
                    else if(Kil){
                        VMPrint("    %3d,%03d ", Kil, One);
                    }
                    else if(0 == (DirectoryEntry.DAttributes & VM_FILE_SYSTEM_ATTR_DIRECTORY)){
                        VMPrint("        %3d ",One);
                    }
                    else{
                        VMPrint("            ");   
                    }
                    VMPrint("%-13s %s\n",DirectoryEntry.DShortFileName, DirectoryEntry.DLongFileName);
                }
                VMDirectoryClose(DirDescriptor);
            }
            else{
                VMPrint("Failed to open directory %s!\n", DirectoryName);   
            }
        }
        else if(StringMatchN(LineBuffer,"cd ",3)){
            CharactersIn = 2;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryChange(LineBuffer + CharactersIn)){
                VMPrint("Failed to change directory to %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"rm ",3)){
            CharactersIn = 2;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryUnlink(LineBuffer + CharactersIn)){
                VMPrint("Failed to remove node %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"mkdir ",6)){
            CharactersIn = 5;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryCreate(LineBuffer + CharactersIn)){
                VMPrint("Failed to create directory %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"cat ",4)){
            CharactersIn = 3;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if(VM_STATUS_SUCCESS == VMFileOpen(LineBuffer + CharactersIn, O_RDONLY, 0644, &FileDescriptor)){
                Length = sizeof(LineBuffer);
                while(VM_STATUS_SUCCESS == VMFileRead(FileDescriptor, LineBuffer, &Length)){
                    if(Length){
                        VMFileWrite(1,LineBuffer,&Length);
                    }
                    if(Length < sizeof(LineBuffer)){
                        break;
                    }
                    Length = sizeof(LineBuffer);
                }
                VMFileClose(FileDescriptor);
            }
            else{
                VMPrint("Failed to open file %s!\n", LineBuffer + CharactersIn);
            }
        }
    }
}