extern "C" int main(int argc, char *argv[]) { checkpointNext("Names:"); testAlloc(" NULL", NULL, 1, 0x100, NULL); testAlloc(" Blank", "", 1, 0x100, NULL); testAlloc(" Long", "123456789012345678901234567890123456789012345678901234567890", 1, 0x100, NULL); checkpointNext("Types:"); static const int types[] = {-1, 0, 1, 2, 3, 4, 5, 0x11, 0x101, 0x1001, 0x10001, 0x100001, 0x1000001, 0x10000001}; for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { char temp[32]; sprintf(temp, " Type %x", types[i]); testAlloc(temp, "test", types[i], 0x100, NULL); } checkpointNext("Sizes:"); static const int sizes[] = {-1, 0, 1, 2, 3, 4, 5, 0x11, 0x101, 0x1001, 0x10001}; for (size_t i = 0; i < ARRAY_SIZE(sizes); ++i) { SceUID uid1 = sceKernelAllocMemoryBlock("test", 1, 0x100, NULL); SceUID uid2 = sceKernelAllocMemoryBlock("test", 1, sizes[i], NULL); if (uid2 >= 0) { u8 *ptr1; u8 *ptr2; sceKernelGetMemoryBlockPtr(uid1, (void **) &ptr1); sceKernelGetMemoryBlockPtr(uid2, (void **) &ptr2); checkpoint(" Size %x: OK, delta=%x", sizes[i], ptr1 - ptr2); } else { checkpoint(" Size %x: Failed (%08x)", sizes[i], uid2); } } checkpointNext("Param sizes:"); u32 params[2]; static const int paramSizes[] = {-1, 0, 1, 2, 3, 4, 5, 0x11, 0x101, 0x1001, 0x10001, 0x100001, 0x1000001, 0x10000001}; for (size_t i = 0; i < ARRAY_SIZE(paramSizes); ++i) { char temp[32]; sprintf(temp, " Type %x", paramSizes[i]); params[0] = paramSizes[i]; params[1] = 0x100; testAlloc(temp, "test", 1, 0x100, params); } checkpointNext("Partition usage:"); void *ptr; SceUID uid = sceKernelAllocMemoryBlock("test", 1, 0x100, NULL); checkpoint(" sceKernelGetBlockHeadAddr: %08x", sceKernelGetBlockHeadAddr(uid) == NULL ? NULL : 0x1337); checkpoint(" sceKernelFreePartitionMemory: %08x", sceKernelFreePartitionMemory(uid)); uid = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "test", PSP_SMEM_High, 0x100, NULL); checkpoint(" sceKernelGetMemoryBlockPtr: %08x", sceKernelGetMemoryBlockPtr(uid, &ptr)); checkpoint(" sceKernelFreeMemoryBlock: %08x", sceKernelFreeMemoryBlock(uid)); checkpointNext("Invalid uids:"); checkpoint(" Free: %08x", sceKernelFreeMemoryBlock(uid)); checkpoint(" BlockPtr: %08x", sceKernelGetMemoryBlockPtr(uid, &ptr)); return 0; }
int main(int argc, char *argv[]) { int i; char temp[128]; setup(); testAlloc("Normal", PSP_MEMORY_PARTITION_USER, "test", 0, 0x10, NULL); printf("\nNames:\n"); testAlloc(" NULL name", PSP_MEMORY_PARTITION_USER, NULL, 0, 0x1000, NULL); testAlloc(" Blank name", PSP_MEMORY_PARTITION_USER, "", 0, 0x1000, NULL); testAlloc(" Long name", PSP_MEMORY_PARTITION_USER, "1234567890123456789012345678901234567890123456789012345678901234", 0, 0x1000, NULL); printf("\nPartitions:\n"); int parts[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; for (i = 0; i < sizeof(parts) / sizeof(parts[0]); ++i) { sprintf(temp, " Partition %d", parts[i]); testAlloc(temp, parts[i], "part", 0, 0x1000, NULL); } printf("\nTypes:\n"); unsigned int types[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { sprintf(temp, " Type %d", types[i]); testAlloc(temp, PSP_MEMORY_PARTITION_USER, "type", types[i], 0x1000, NULL); } printf("\nSizes:\n"); unsigned int sizes[] = { -1, 0, 1, 0x10, 0x20, 0x2F, 0x30, 0x31, 0x32, 0x36, 0x38, 0x39, 0x3A, 0x131, 0x136, 0x139, 0x1000, 0x10000, 0x100000, 0x1000000, 0x10000000, 0x1800000, 0x2000000, }; for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) { sprintf(temp, " Size 0x%08X", sizes[i]); testAlloc(temp, PSP_MEMORY_PARTITION_USER, "size", 0, sizes[i], NULL); } printf("\nPositions:\n"); testAlloc(" Wrong type", PSP_MEMORY_PARTITION_USER, "pos", 0, 0x1000, high - 0x1000); testAlloc(" Below low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low - 0x1000); testAlloc(" At low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low); testAlloc(" Above low", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, low + 0x1000); testAlloc(" Near high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high - 0x1000); testAlloc(" At high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high); testAlloc(" Above high", PSP_MEMORY_PARTITION_USER, "pos", 2, 0x1000, high + 0x1000); SceUID posPart1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 2, 0x1000, low); char *pos1 = (char *)sceKernelGetBlockHeadAddr(posPart1); testAlloc(" Second at low", PSP_MEMORY_PARTITION_USER, "part2", 2, 0x1000, low); char *pos2 = testAlloc(" Second type low", PSP_MEMORY_PARTITION_USER, "part2", 0, 0x1000, low); printf(" Difference: %X\n", pos2 - pos1); sceKernelFreePartitionMemory(posPart1); printf("\nAlignment:\n"); SceUID alignbase[0x1000]; int alignbaseCount; for (alignbaseCount = 0; alignbaseCount < 0x1000; ++alignbaseCount) { alignbase[alignbaseCount] = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "alignbase", 0, 0x1, NULL); char *base = (char *)sceKernelGetBlockHeadAddr(alignbase[alignbaseCount]); if (((u32)base & 0xFFF) == 0xF00) break; } SceUID alignLowID = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 3, 0x1000, (void *)0x1000); SceUID alignHighID = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 4, 0x1000, (void *)0x1000); char *alignLow = (char *)sceKernelGetBlockHeadAddr(alignLowID); char *alignHigh = (char *)sceKernelGetBlockHeadAddr(alignHighID); unsigned int aligns[] = { -5, -1, 0, 1, 2, 3, 4, 7, 8, 0x10, 0x11, 0x20, 0x2F, 0x40, 0x60, 0x80, 0x100, 0x1000, 0x2000, 0x1000000, 0x4000000, 0x40000000, 0x80000000, }; for (i = 0; i < sizeof(aligns) / sizeof(aligns[0]); ++i) { sprintf(temp, " Align 0x%08X low", aligns[i]); testAllocDiff(temp, PSP_MEMORY_PARTITION_USER, "part2", 3, 0x1000, (char *)aligns[i], 0, alignLow); sprintf(temp, " Align 0x%08X high", aligns[i]); testAllocDiff(temp, PSP_MEMORY_PARTITION_USER, "part2", 4, 0x1000, (char *)aligns[i], 1, alignHigh); } sceKernelFreePartitionMemory(alignLowID); while (alignbaseCount >= 0) { sceKernelFreePartitionMemory(alignbase[alignbaseCount--]); } sceKernelFreePartitionMemory(alignHighID); printf("\n"); SceUID part1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 0, 0x1, NULL); SceUID part2 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 0, 0x1, NULL); if (part1 > 0 && part2 > 0) { printf("Two with same name: OK\n"); } else { printf("Two with same name: Failed (%08X, %08X)\n", part1, part2); } char *part1Pos = (char *)sceKernelGetBlockHeadAddr(part1); char *part2Pos = (char *)sceKernelGetBlockHeadAddr(part2); printf("Minimum difference: %x\n", part2Pos - part1Pos); sceKernelFreePartitionMemory(part1); sceKernelFreePartitionMemory(part2); part1 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part1", 3, 0x101, (void *)1); part2 = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part2", 3, 0x101, (void *)1); part1Pos = (char *)sceKernelGetBlockHeadAddr(part1); part2Pos = (char *)sceKernelGetBlockHeadAddr(part2); printf("Offset difference: %x\n", part2Pos - part1Pos); sceKernelFreePartitionMemory(part1); sceKernelFreePartitionMemory(part2); SceUID reschedThread = sceKernelCreateThread("resched", &reschedFunc, sceKernelGetThreadCurrentPriority(), 0x1000, 0, NULL); sceKernelStartThread(reschedThread, 0, NULL); SceUID reschedPart = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "part", 0, 0x1000, NULL); sceKernelGetBlockHeadAddr(reschedPart); sceKernelFreePartitionMemory(reschedPart); sceKernelTerminateDeleteThread(reschedThread); printf("Reschedule: %s\n", didResched ? "yes" : "no"); SceUID allocs[1024]; int result = 0; for (i = 0; i < 1024; i++) { allocs[i] = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "create", 0, 0x100, NULL); if (allocs[i] < 0) { result = allocs[i]; break; } } if (result != 0) printf("Create 1024: Failed at %d (%08X)\n", i, result); else printf("Create 1024: OK\n"); while (--i >= 0) sceKernelFreePartitionMemory(allocs[i]); printf("Get deleted: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(reschedPart)); printf("Get NULL: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(0)); printf("Get invalid: %08X\n", (unsigned int)sceKernelGetBlockHeadAddr(0xDEADBEEF)); printf("Free deleted: %08X\n", sceKernelFreePartitionMemory(reschedPart)); printf("Free NULL: %08X\n", sceKernelFreePartitionMemory(0)); printf("Free invalid: %08X\n", sceKernelFreePartitionMemory(0xDEADBEEF)); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { testAlloc(); CommonLib::CBitsVector bitVectors; bool bBit = false; for (size_t i = 0; i < 10000; ++i) { bitVectors.push_back(bBit); bBit = !bBit; } for (size_t i = 0; i < 10000; ++i) { bool bBitt = bitVectors[bBit]; bBit = !bBit; } int nBitCount = 8; int nByte = nBitCount/8; int nBit = nBitCount%8; Int128 a1(2, 0xFFFFFFFFFFFFFFFF); Int128 a2(1, 1); Int128 res = a1 + a2; uint64 dd = 0; uint64 dd1 = 0; uint64 dd2 =100; dd = (dd1 - 1); if(dd > (dd + 1)) { int rr = 0; rr++; } int i = 0; int j = i++; CommonLib::alloc_t *alloc = new CommonLib::simple_alloc_t(); CommonLib::CWriteMemoryStream memStream(alloc); memStream.resize(50); CommonLib::FxBitWriteStream bitWrite; CommonLib::FxBitReadStream bitRead; bitWrite.attach(&memStream, 0, 50); bitRead.attach(&memStream, 0, 50); uint32 nVal1111 = 32; int64 nValue = 0; int len = embDB::BitsUtils::log2(nVal1111); int len2 = embDB::BitsUtils::log2((uint32)1); int len3 = embDB::BitsUtils::log2((uint32)2); bitWrite.writeBits(nVal1111, len + 1); bitRead.readBits(nValue, len); bitWrite.writeBits(nValue, 1); nValue = -1024; bitWrite.writeBits(nValue, 64); int64 nReadValue = 1; bitRead.readBits(nReadValue, 1); bitRead.readBits(nReadValue, 64); bitWrite.writeBits(nValue, 11); /*CommonLib::CWriteFileStream writeFSteam; writeFSteam.open(L"D:\\1.fs", CommonLib::ofmCreateAlways, CommonLib::arWrite, CommonLib::smNoMode); writeFSteam.write((uint64)23); writeFSteam.write((uint32)15); writeFSteam.write((byte)1); writeFSteam.close(); CommonLib::CReadFileStream readFSteam; readFSteam.open(L"D:\\1.fs", CommonLib::ofmOpenExisting, CommonLib::arRead, CommonLib::smNoMode); uint64 retu64 = readFSteam.readIntu64(); uint64 retu32 = readFSteam.readIntu32(); byte retByte = readFSteam.readByte(); readFSteam.close(); memStream.write((uint64)23); memStream.write((uint32)15); memStream.write((byte)1); readStrim.attachBuffer(memStream.buffer(), memStream.size()); uint64 nType; readStrim.read(nType); CommonLib::FxMemoryWriteStream writeStrim(alloc); std::vector<CommonLib::CString> vecFiles; CommonLib::FileSystem::getFiles(CommonLib::CString(L"D:\\2\\") + L"*.shp", vecFiles); CommonLib::CString path(L"C:\\test\\ddf\\1.shp"); CommonLib::CString path1(L"C:\\test\\ddf\\"); CommonLib::CString path2(L"C:\\test\\ddf\\1"); CommonLib::CString path3(L"C:\\test\\ddf\\1."); CommonLib::CString path4(L"2.shp"); CommonLib::CString path5(L"2."); CommonLib::CString path6(L"vdfvdfvfd"); CommonLib::CString sFile = CommonLib::FileSystem::FindFileName(path); CommonLib::CString sFile1 = CommonLib::FileSystem::FindFileName(path1); CommonLib::CString sFile2 = CommonLib::FileSystem::FindFileName(path2); CommonLib::CString sFile3 = CommonLib::FileSystem::FindFileName(path3); CommonLib::CString sOnlyFile = CommonLib::FileSystem::FindOnlyFileName(path); CommonLib::CString sOnlyFile1 = CommonLib::FileSystem::FindOnlyFileName(path1); CommonLib::CString sOnlyFile2 = CommonLib::FileSystem::FindOnlyFileName(path2); CommonLib::CString sOnlyFile3 = CommonLib::FileSystem::FindOnlyFileName(path3); CommonLib::CString sOnlyFile4 = CommonLib::FileSystem::FindOnlyFileName(path4); CommonLib::CString sOnlyFile5 = CommonLib::FileSystem::FindOnlyFileName(path5); CommonLib::CString sOnlyFile6 = CommonLib::FileSystem::FindOnlyFileName(path6); CommonLib::CString sExt = CommonLib::FileSystem::FindFileExtension(path); CommonLib::CString sExt1 = CommonLib::FileSystem::FindFileExtension(path1); CommonLib::CString sExt2 = CommonLib::FileSystem::FindFileExtension(path2); CommonLib::CString sExt3 = CommonLib::FileSystem::FindFileExtension(path3); CommonLib::CString sph = CommonLib::FileSystem::FindFilePath(path); CommonLib::CString sph1 = CommonLib::FileSystem::FindFilePath(path1); CommonLib::CString sph2 = CommonLib::FileSystem::FindFilePath(path2); CommonLib::CString sph3 = CommonLib::FileSystem::FindFilePath(path3); testAlloc(); return 0; CommonLib::FxBitWriteStream writeBitStream(alloc); CommonLib::FxBitReadStream readBitStream(alloc); writeBitStream.create(1000); uint16 nBit16_14 = (1 << 13) + (1 << 12) + (1 << 10) + (1 << 5); uint16 nBit16 = 0xffff; uint32 nBit32_30 = (1 << 29) + (1 << 15) + (1 << 7) + (1 << 3); uint32 nBit32 = 0xffffffff; uint64 nBit64_60 = ((uint64)1 << 59) + ((uint64)1 << 30) + ((uint64)1 << 15) + ((uint64)1 << 3); uint64 nBit64 = 0xffffffffffffffff; uint16 nBit16_14_r; uint16 nBit16_r; uint32 nBit32_30_r; uint32 nBit32_r; uint64 nBit64_60_r; uint64 nBit64_r; //writeBitStream.writeBits(nBit16, 15) writeBitStream.writeBit((byte)1); writeBitStream.writeBit((byte)0); writeBitStream.writeBit((byte)1); writeBitStream.writeBit((byte)0); writeBitStream.writeBit((byte)1); writeBitStream.writeBit((byte)0); writeBitStream.writeBit((byte)1); writeBitStream.writeBit((byte)0); writeBitStream.writeBit((byte)1); writeBitStream.writeBits(nBit16_14, 14); writeBitStream.writeBits(nBit16, 16); writeBitStream.writeBits(nBit32_30, 30); writeBitStream.writeBits(nBit32, 32); writeBitStream.writeBits(nBit64_60, 60); writeBitStream.writeBits(nBit64, 64); byte bBit1, bBit2, bBit3, bBit4, bBit5, bBit6, bBit7, bBit8, bBit9; readBitStream.readBits(nBit16_14_r, 14); readBitStream.readBits(nBit16_r, 16); readBitStream.readBits(nBit32_30_r, 30); readBitStream.readBits(nBit32_r, 32); readBitStream.readBits(nBit64_60_r, 60); readBitStream.readBits(nBit64_r, 64); /*CommonLib::CString str; CommonLib::MemoryStream stream(alloc); str.format("dgf %s", "dd"); str.wstr(); int i1 = 666; float f1 = 237.4556; double d1 = 237.4556; bool b1 = true; stream.write(i1); stream.write(f1); stream.write(d1); stream.write(b1); stream.reset(); int i2; float f2; double d2; bool b2; stream.read(i2); stream.read(f2); stream.read(d2); stream.read(b2);*/ return 0; }
void FileAllocator::test(){ testAlloc(); //TODO: fa.toBuffer(buffer); //TODO: fa = FileAllocator::fromBuffer() }
int main(int argc, char **argv) { SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL); void *data; schedf("No timeout:\n"); testAlloc(" More than free", vpl, 0xFFE1, 1); testAlloc(" 0 bytes", vpl, 0, 1); testAlloc(" 1 byte", vpl, 1, 1); testAlloc(" -1 bytes", vpl, -1, 1); testAlloc(" 16 bytes", vpl, 16, 1); testAlloc(" 8 bytes", vpl, 8, 1); schedf("\nWith timeout:\n"); testAllocTimeout(" More than free", vpl, 0xFFE1, 500, 1); testAllocTimeout(" 0 bytes", vpl, 0, 500, 1); testAllocTimeout(" 1 byte", vpl, 1, 500, 1); testAllocTimeout(" -1 bytes", vpl, -1, 500, 1); testAllocTimeout(" 16 bytes", vpl, 16, 500, 1); testAllocTimeout(" 8 bytes", vpl, 8, 500, 1); schedf("\nErrors:\n"); // Crashes. //testAllocTimeout("Into NULL", vpl, 8, 500, 0); testAllocTimeout(" Into NULL", vpl, 0xFFE0, 500, 0); testAllocTimeout(" Most remaining", vpl, 0xFF00, 500, 1); testAllocTimeout(" More than remaining", vpl, 0xA1, 500, 1); testAllocTimeout(" All remaining", vpl, 0x68, 500, 1); testAllocTimeout(" All remaining - 7", vpl, 0x68 - 7, 500, 1); testAllocTimeout(" All remaining - 8", vpl, 0x68 - 8, 500, 1); testAllocTimeout(" 1 byte (none left)", vpl, 1, 500, 1); testAllocTimeout(" 1 byte (none left, 0 timeout)", vpl, 1, 0, 1); sceKernelDeleteVpl(vpl); testAllocTimeout(" NULL", 0, 0x100, 500, 1); testAllocTimeout(" NULL with invalid", 0, 0, 500, 0); testAllocTimeout(" Invalid", 0xDEADBEEF, 0x100, 500, 1); testAllocTimeout(" Deleted", vpl, 0x100, 500, 1); schedf("\n"); testDiff(); u32 attrs[] = {PSP_VPL_ATTR_FIFO, PSP_VPL_ATTR_PRIORITY, PSP_VPL_ATTR_SMALLEST, PSP_VPL_ATTR_HIGHMEM}; int i; for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); ++i) { schedf("Attr %x:\n", attrs[i]); testAllocThread(" Alloc 0x10 of 0x00/0xE0", attrs[i], 0x20, 0xE0 - 0x08); testAllocThread(" Alloc 0x10 of 0x20/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08)); testAllocThread(" Alloc 0x10 of 0x40/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08) * 2); schedf("\n"); } flushschedf(); SceUID deleteThread = CREATE_SIMPLE_THREAD(deleteMeFunc); vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL); sceKernelAllocateVpl(vpl, 0x10000 - 0x20 - 0x08, &data, NULL); sceKernelStartThread(deleteThread, sizeof(SceUID), &vpl); sceKernelDeleteVpl(vpl); flushschedf(); unsigned int timeout; BASIC_SCHED_TEST("Zero", timeout = 500; result = sceKernelAllocateVpl(vpl1, 0, &data, &timeout); );