Files
ppsspp/unittest/TestVFS.cpp
T
libretroadmin f1208a7a5a Make threading lock-free
The core and the headless tools no longer use mutexes, condition variables,
spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through
libretro-common's retro_atomic and rthreads plus a few small pieces on top of
them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and
ReaderGate. Every wait blocks until it's woken; nothing polls on a timer.

State that only one thread touches just loses its lock. The PSP filesystem,
sceIo and the savedata dialog now belong to the emulation thread: async reads
and writes run when they're queued and complete later in emulated time, and
the IO and savedata threads are gone. The friend finder only talks to the
adhoc server and hands what it gets to the emulation thread. GPU init always
runs on the thread that starts the game.

The Vulkan render and compile queues, pipeline and render pass caches, delete
list and SPIR-V cache, the GL render queue, the software renderer's jit caches,
the file loader caches, the web debugger, UPnP, input, savestates, logging and
the GE debugger all hand off through queues and atomics. The IR jit's spinning
profiler thread goes.

A CPU thread with nothing to run now sleeps until work is queued instead of
spinning. Headless with --debugger waits for a client while stopped, and ends
the run once every client that connected has left. Web server shutdown keeps
servicing the CPU queue until the server has finished.
2026-10-09 04:56:16 +02:00

94 lines
2.6 KiB
C++

#include <vector>
#include "Common/Log.h"
#include "Common/File/VFS/ZipFileReader.h"
#include "UnitTest.h"
static bool CheckContainsDir(const std::vector<File::FileInfo> &listing, const char *name) {
for (auto &file : listing) {
if (file.name == name && file.isDirectory) {
return true;
}
}
return false;
}
static bool CheckContainsFile(const std::vector<File::FileInfo> &listing, const char *name) {
for (auto &file : listing) {
if (file.name == name && !file.isDirectory) {
return true;
}
}
return false;
}
// ziptest.zip file structure:
//
// ziptest/
// data/
// a/
// in_a.txt
// b/
// in_b.txt
// argh.txt
// big.txt
// lang/
// en_us.txt
// sv_se.txt
// langregion.txt
// in_root.txt
// TODO: Also test the filter.
bool TestZipFile() {
// First, check things relative to root, with an empty internal path.
Path zipPath = Path("../source_assets/ziptest.zip");
if (!File::Exists(zipPath)) {
zipPath = Path("source_assets/ziptest.zip");
}
ZipFileReader *dir = ZipFileReader::Create(zipPath, "", true);
EXPECT_TRUE(dir != nullptr);
std::vector<File::FileInfo> listing;
EXPECT_TRUE(dir->GetFileListing("", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 2);
EXPECT_TRUE(CheckContainsDir(listing, "ziptest"));
EXPECT_TRUE(CheckContainsFile(listing, "in_root.txt"));
EXPECT_FALSE(dir->GetFileListing("ziptestwrong", &listing, nullptr));
// Next, do a file listing in a directory, but keep the root.
EXPECT_TRUE(dir->GetFileListing("ziptest", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 3);
EXPECT_TRUE(CheckContainsDir(listing, "data"));
EXPECT_TRUE(CheckContainsDir(listing, "lang"));
EXPECT_TRUE(CheckContainsFile(listing, "langregion.txt"));
delete dir;
// Next, we'll destroy the reader and create a new one based in a subdirectory.
dir = ZipFileReader::Create(zipPath, "ziptest/data", true);
EXPECT_TRUE(dir != nullptr);
EXPECT_TRUE(dir->GetFileListing("", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 4);
EXPECT_TRUE(CheckContainsDir(listing, "a"));
EXPECT_TRUE(CheckContainsDir(listing, "b"));
EXPECT_TRUE(CheckContainsFile(listing, "argh.txt"));
EXPECT_TRUE(CheckContainsFile(listing, "big.txt"));
EXPECT_TRUE(dir->GetFileListing("a", &listing, nullptr));
EXPECT_TRUE(CheckContainsFile(listing, "in_a.txt"));
EXPECT_EQ_INT(listing.size(), 1);
EXPECT_TRUE(dir->GetFileListing("b", &listing, nullptr));
EXPECT_TRUE(CheckContainsFile(listing, "in_b.txt"));
EXPECT_EQ_INT(listing.size(), 1);
delete dir;
return true;
}
bool TestVFS() {
if (!TestZipFile())
return false;
return true;
}