diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 16:16:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 16:16:03 -0400 |
| commit | f64d8748d4396a90d27adbdc17db3bac4a58d666 (patch) | |
| tree | 14d254a2666b9df86286d6964519669b007bc6db | |
| parent | be8497804f803c02cfab1aa2c54d921042e90ec9 (diff) | |
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.
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 71 |
1 files 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<IArtifact>& outArtifact) { // We need to extract the binary List<uint8_t> 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<ISlangSharedLibrary>& outSharedLibrary) +{ + ComPtr<IArtifact> artifact; + SLANG_RETURN_ON_FAIL(_createArtifactFromHexDump(hexDump, ArtifactDesc::make(ArtifactKind::SharedLibrary, ArtifactPayload::HostCPU, ArtifactStyle::Unknown), artifact)); + ComPtr<ICastable> castable; + SLANG_RETURN_ON_FAIL(artifact->getOrCreateRepresentation(ISlangSharedLibrary::getTypeGuid(), ArtifactKeep::Yes, castable.writeRef())); + outSharedLibrary = as<ISlangSharedLibrary>(castable); + return SLANG_OK; +} - fileName.append(Process::getExecutableSuffix()); +static SlangResult _executeBinary(const UnownedStringSlice& hexDump, ExecuteResult& outExeRes) +{ + ComPtr<IArtifact> artifact; + SLANG_RETURN_ON_FAIL(_createArtifactFromHexDump(hexDump, ArtifactDesc::make(ArtifactKind::Executable, ArtifactPayload::HostCPU, ArtifactStyle::Unknown), artifact)); - temporaryFileSet.add(fileName); - - { - ComPtr<ISlangWriter> writer; - SLANG_RETURN_ON_FAIL(FileWriter::createBinary(fileName.getBuffer(), 0, writer)); + ComPtr<IOSFileArtifactRepresentation> 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<uint8_t> 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<ISlangWriter> 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); |
