From f64d8748d4396a90d27adbdc17db3bac4a58d666 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 1 Sep 2022 16:16:03 -0400 Subject: Use Artifact in slang-test (#2385) * #include an absolute path didn't work - because paths were taken to always be relative. * Make DownstreamCompileOptions use POD types. * CharSliceAllocator -> SliceAllocator Added SliceConverter CharSliceCaster -> SliceCaster * First attempt at zero terminating around blobs. * Fix clang warning. * Add SlangTerminatedChars Make Blob implementations support it. Make most blobs 'terminated'. * Fix bug setting up sourceFiles for CommandLineDownstreamCompiler. * Traffic in TerminatedCharSlice for sourceFiles. Use ArtifactDesc to generate temporary file names for source. * Fix typo in testing for shared library/C++. * Working with source being passed as artifacts to DownstreamCompiler. * Use artifacts in SourceManager/SourceFile. * Support infering extension from the original file extension. * * Infer extension if can't determine from the artifact type * Split IOSFile/IExtFile representations * Move responsibility for creating OS file to the handler. * Disable the check memory path. * Remove artifact from SourceFile. Lazily generate SourceFile from artifacts as needed. * Fix some small bugs. * Remove maybeAddArtifact. * Load artifacts if repro capture is enabled. * Remove adding by string, because doing so means source will be allocated twice or there is a potential race around ref counting to the contained String. * Add built in source as a blob. * Fix warning. * Make StringBlob own the contents if moved. Fix some compilation issues. * Share StringBlob uniqueness code. * Do move unique on Ctor. * Use artifact in slang-test. --- tools/slang-test/slang-test-main.cpp | 71 ++++++++++++------------------------ 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index e30b7dd8c..a767f4f3b 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1202,33 +1202,39 @@ TestResult asTestResult(ToolReturnCode code) } \ } -static SlangResult _executeBinary(const UnownedStringSlice& hexDump, ExecuteResult& outExeRes) +static SlangResult _createArtifactFromHexDump(const UnownedStringSlice& hexDump, const ArtifactDesc& desc, ComPtr& outArtifact) { // We need to extract the binary List data; SLANG_RETURN_ON_FAIL(HexDumpUtil::parseWithMarkers(hexDump, data)); - TemporaryFileSet temporaryFileSet; - - // Need to write this off to a temporary file + auto blob = ListBlob::moveCreate(data); + auto artifact = ArtifactUtil::createArtifact(desc); + artifact->addRepresentationUnknown(blob); - String temporaryLockPath; + outArtifact.swap(artifact); + return SLANG_OK; +} - SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice("slang-test"), temporaryLockPath)); - String fileName = temporaryLockPath; - // And the temporary lock path - temporaryFileSet.add(temporaryLockPath); +static SlangResult _loadAsSharedLibrary(const UnownedStringSlice& hexDump, TemporaryFileSet& inOutTemporaryFileSet, ComPtr& outSharedLibrary) +{ + ComPtr artifact; + SLANG_RETURN_ON_FAIL(_createArtifactFromHexDump(hexDump, ArtifactDesc::make(ArtifactKind::SharedLibrary, ArtifactPayload::HostCPU, ArtifactStyle::Unknown), artifact)); + ComPtr castable; + SLANG_RETURN_ON_FAIL(artifact->getOrCreateRepresentation(ISlangSharedLibrary::getTypeGuid(), ArtifactKeep::Yes, castable.writeRef())); + outSharedLibrary = as(castable); + return SLANG_OK; +} - fileName.append(Process::getExecutableSuffix()); +static SlangResult _executeBinary(const UnownedStringSlice& hexDump, ExecuteResult& outExeRes) +{ + ComPtr artifact; + SLANG_RETURN_ON_FAIL(_createArtifactFromHexDump(hexDump, ArtifactDesc::make(ArtifactKind::Executable, ArtifactPayload::HostCPU, ArtifactStyle::Unknown), artifact)); - temporaryFileSet.add(fileName); - - { - ComPtr writer; - SLANG_RETURN_ON_FAIL(FileWriter::createBinary(fileName.getBuffer(), 0, writer)); + ComPtr fileRep; + SLANG_RETURN_ON_FAIL(artifact->requireFile(ArtifactKeep::Yes, fileRep.writeRef())); - SLANG_RETURN_ON_FAIL(writer->write((const char*)data.getBuffer(), data.getCount())); - } + const auto fileName = fileRep->getPath(); // Make executable... (for linux/unix like targets) SLANG_RETURN_ON_FAIL(File::makeExecutable(fileName)); @@ -2011,37 +2017,6 @@ TestResult runCompile(TestContext* context, TestInput& input) return TestResult::Pass; } - -static SlangResult _loadAsSharedLibrary(const UnownedStringSlice& hexDump, TemporaryFileSet& inOutTemporaryFileSet, SharedLibrary::Handle& outSharedLibrary) -{ - // We need to extract the binary - List data; - SLANG_RETURN_ON_FAIL(HexDumpUtil::parseWithMarkers(hexDump, data)); - - // Need to write this off to a temporary file - - String temporaryLockPath; - SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice("slang-test"), temporaryLockPath)); - inOutTemporaryFileSet.add(temporaryLockPath); - - String fileName = temporaryLockPath; - - // Need to work out the dll name - String sharedLibraryName = SharedLibrary::calcPlatformPath(fileName.getUnownedSlice()); - inOutTemporaryFileSet.add(sharedLibraryName); - - { - ComPtr writer; - SLANG_RETURN_ON_FAIL(FileWriter::createBinary(sharedLibraryName.getBuffer(), 0, writer)); - SLANG_RETURN_ON_FAIL(writer->write((const char*)data.getBuffer(), data.getCount())); - } - - // Make executable... (for linux/unix like targets) - //SLANG_RETURN_ON_FAIL(File::makeExecutable(fileName)); - - return SharedLibrary::loadWithPlatformPath(sharedLibraryName.getBuffer(), outSharedLibrary); -} - TestResult runSimpleCompareCommandLineTest(TestContext* context, TestInput& input) { TestInput workInput(input); -- cgit v1.2.3