public async Task ClientTest_Docker() { if (!Debugger.IsAttached) { Assert.Inconclusive("Run local service and debug this test"); } var testDataRoot = Path.Combine(Directory.GetCurrentDirectory(), "client", "TestDataDocker"); var context = new RISCVIntegrationContext() .WithExtensionClasses(new ExtensionClasses().Text("sh")) .WithRootFolder(testDataRoot) .WithAllRegisteredFiles() .WithOperations( new BashInvocation("chmod 777 ./1.sh"), new ResetRules(), // new BashInvocation("mkdir output"), new BashInvocation("./1.sh") ) .TakeModifiedFiles() ; var result = await RISCVIntegrationClient.Run(context); Assert.IsNotNull(result); }
void FirmwareFromCS() { var csFiles = Directory.EnumerateFiles(SourceFolder); var csFilesContent = csFiles .Select(path => new FSTextFile() { Name = path, Content = File.ReadAllText(path) }) .ToList(); if (csFilesContent.Any()) { foreach (var cs in csFilesContent) { Console.WriteLine($"Found CS source: {cs.Name}"); } // translate source files var tx = new CSharp2CPPTranslator(); var source = new FSSnapshot(); source.Files.AddRange(csFilesContent); tx.Run(source); var firmwareSource = tx.Result; // create soc resource records var socGenerator = new SOCGenerator(); var socRecordsBuilder = new SOCRecordsBuilder(); var socRecords = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources); firmwareSource.Add(socGenerator.SOCImport(socRecords)); FileTools.CreateDirectoryRecursive(FirmwareFolder); var m = new FSManager(FirmwareFolder); m.SaveSnapshot(firmwareSource); } ModifyMakefile(); if (File.Exists(MakefileFile)) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var context = RISCVIntegration .DefaultContext(FirmwareFolder) .WithMakeTarget("bin"); RISCVIntegrationClient.Make(context).Wait(); } else { using (new CurrentDirectory(FirmwareFolder)) { Toolchain.Make("bin"); } } } else { Console.WriteLine($"Makefile was not found: {MakefileFile}"); } }
public async Task MakeTest() { // translate source files var tx = new CSharp2CPPTranslator(); var source = new FSSnapshot(); source.Files.Add(LoadSource("SOCBlinker.cs")); tx.Run(source); var firmwareSource = tx.Result; // create soc resource records var socGenerator = new SOCGenerator(); var socRecordsBuilder = new SOCRecordsBuilder(); var socRecords = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources); firmwareSource.Add(socGenerator.SOCImport(socRecords)); IntermediateData.SaveToMake(firmwareSource); // run makefile var context = RISCVIntegration .DefaultContext(TestPath.MakeFolder) .WithMakeTarget("bin"); await RISCVIntegrationClient.Make(context); }
public async Task ClientTest_Windows() { if (!Debugger.IsAttached) { Assert.Inconclusive("Run local service and debug this test"); } var testDataRoot = Path.Combine(Directory.GetCurrentDirectory(), "client", "TestDataWindows"); var context = new RISCVIntegrationContext() .WithEndpoint(new RISCVIntegrationEndpoint() { Port = 15001 }) .WithExtensionClasses(new ExtensionClasses().Text("cmd")) .WithRootFolder(testDataRoot) .WithAllRegisteredFiles() .WithOperations(new CmdInvocation("1.cmd")) .TakeModifiedFiles() ; var result = await RISCVIntegrationClient.Run(context); Assert.IsNotNull(result); }
public async Task MakeTest_FirmwareFolder() { var context = RISCVIntegration .DefaultContext(TestPath.FirmwareSourceFolder) .WithMakeTarget("firmware.bin"); await RISCVIntegrationClient.Make(context); }
public async Task MakeTest_MakeFolder() { var context = RISCVIntegration .DefaultContext(TestPath.MakeFolder) .WithMakeTarget("bin"); await RISCVIntegrationClient.Make(context); }
public async Task Asm() { var asm = @" addi x1, x0, 10 addi x1, x0, -10 "; var instructions = await RISCVIntegrationClient.Asm(new RISCVIntegrationEndpoint(), asm); Assert.AreEqual(2, instructions.Length); Assert.AreEqual(0x00A00093U, instructions[0]); Assert.AreEqual(0xFF600093U, instructions[1]); }
public QuSoCModuleSimulator FromApp(string appName) { var firmwareTools = new FirmwareTools(AppPath(appName)); Assert.IsTrue(firmwareTools.FirmwareFromAppFolder()); var instructions = RISCVIntegrationClient .ToInstructions(File.ReadAllBytes(firmwareTools.FirmwareFile)) .ToArray(); var sim = PowerUp(instructions); return(sim); }
public uint[] Instructions() { if (!File.Exists(FirmwareFile)) { return(new uint[0]); } var instructions = RISCVIntegrationClient .ToInstructions(File.ReadAllBytes(FirmwareFile)) .ToArray(); return(instructions); }
async Task <FSSnapshot> CompileFromIntermediate() { var context = RISCVIntegration .DefaultContext(TestPath.FirmwareSourceFolder); if (!await RISCVIntegrationClient.HealthCheck(context.Endpoint)) { throw new Exception($"RISCV toolchain not available"); } var result = await RISCVIntegrationClient.Run(context); Assert.IsNotNull(result); return(result.ResultSnapshot); }
public uint[] FromAsmSource(string asmSource) { // making a API call to integration server. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // on Windows, integration server is required to run in Docker or WSL. // Installation steps are same for WSL and for docker. // https://github.com/EvgenyMuryshkin/Quokka.RISCV.Docker var instructions = RISCVIntegrationClient.Asm(new RISCVIntegrationEndpoint(), asmSource); return(instructions.Result); } else { // on Linux, just make local call to RISCV toolchain return(RISCVIntegrationClient.ToInstructions(Toolchain.Asm(asmSource)).ToArray()); } }
void Build(string testName) { // prepare source code for test File.Copy(Path.Combine(SourcesLocation, $"{testName}.S"), Path.Combine(TestLocation, $"{testName}.S")); var Makefile = Path.Combine(TestLocation, "Makefile"); var makeLines = File.ReadAllLines(Makefile); makeLines[0] = $"files = {testName}.S"; File.WriteAllLines(Makefile, makeLines); // make test instructions var context = RISCVIntegration .DefaultContext(TestLocation) .WithMakeTarget("bin"); RISCVIntegrationClient.Make(context).Wait(); }
public async Task ClientTest_Docker_TinyFPGA() { if (!Debugger.IsAttached) { Assert.Inconclusive("Run local service and debug this test"); } var testDataRoot = Path.Combine(Directory.GetCurrentDirectory(), "client", "TinyFPGA-BX"); var context = new RISCVIntegrationContext() .WithExtensionClasses( new ExtensionClasses() .Text("sh") .Text("") .Text("lds") .Text("s") .Text("c") .Text("cpp") .Binary("bin") .Binary("elf") .Text("map") ) .WithRootFolder(testDataRoot) .WithAllRegisteredFiles() .WithOperations( new BashInvocation("make firmware.bin") ) .TakeModifiedFiles() ; var result = await RISCVIntegrationClient.Run(context); Assert.IsNotNull(result); var binFile = result.ResultSnapshot.Files.Find(f => f.Name == "firmware.bin"); Assert.IsNotNull(binFile); }
uint[] Instructions() { var instructions = RISCVIntegrationClient.ToInstructions(File.ReadAllBytes(FirmwareFile)).ToArray(); return(instructions); }
async Task RunWithData( List <SOCRecord> externalData, string mainCode) { var textReplacer = new TextReplacer(); var templateRoot = TemplatesPath(Path.GetDirectoryName(Directory.GetCurrentDirectory())); var sourceRoot = @"C:\code\Quokka.RISCV.Docker.Server\Quokka.RISCV.Integration.Tests\Client\Blinker\Source"; var context = new RISCVIntegrationContext() .WithExtensionClasses( new ExtensionClasses() .Text("") .Text("lds") .Text("s") .Text("c") .Text("cpp") .Text("h") .Binary("bin") .Binary("elf") .Text("map") ) .WithRootFolder(sourceRoot) .WithAllRegisteredFiles() .WithOperations( new BashInvocation("make firmware.bin") ) .TakeModifiedFiles() ; var firmwareTemplatePath = File.ReadAllText(Path.Combine(templateRoot, "firmware.template.cpp")); var firmwareMap = new Dictionary <string, string>() { { "MAIN_CODE", mainCode } }; firmwareTemplatePath = textReplacer.ReplaceToken(firmwareTemplatePath, firmwareMap); var dmaGenerator = new SOCGenerator(); context.SourceSnapshot.Files.Add(dmaGenerator.SOCImport(externalData)); var generator = new IntegrationGenerator(); context.SourceSnapshot.Files.Add(generator.Firmware(firmwareTemplatePath)); new FSManager(sourceRoot).SaveSnapshot(context.SourceSnapshot); var result = await RISCVIntegrationClient.Run(context); Assert.IsNotNull(result); var hardwareTemplatePath = Path.Combine(templateRoot, "hardware.template.v"); var hardwareTemplate = File.ReadAllText(hardwareTemplatePath); // memory init file var binFile = (FSBinaryFile)result.ResultSnapshot.Files.Find(f => f.Name == "firmware.bin"); Assert.IsNotNull(binFile); var replacers = new Dictionary <string, string>(); var words = TestTools.ReadWords(binFile.Content).ToList(); var memInit = generator.MemInit(words, "l_mem", 512, 4); replacers["MEM_INIT"] = memInit; // data declarations replacers["DATA_DECL"] = generator.DataDeclaration(externalData); // data control signals var templates = new IntegrationTemplates(); foreach (var templatePath in Directory.EnumerateFiles(templateRoot, "*.*", SearchOption.AllDirectories)) { var name = Path.GetFileName(templatePath).Split('.')[0]; templates.Templates[name] = File.ReadAllText(templatePath); } replacers["DATA_CTRL"] = generator.DataControl(externalData, templates); replacers["MEM_READY"] = generator.MemReady(externalData); replacers["MEM_RDATA"] = generator.MemRData(externalData); hardwareTemplate = textReplacer.ReplaceToken(hardwareTemplate, replacers); File.WriteAllText(@"C:\code\picorv32\quartus\RVTest.v", hardwareTemplate); }
public bool FirmwareFromAppFolder() { if (!SourceExists) { return(false); } // delete old firmware before making new one if (File.Exists(FirmwareFile)) { File.Delete(FirmwareFile); } var appName = Path.GetFileName(appPath); var sourceFolder = Path.Combine(appPath, "source"); var firmwareFolder = Path.Combine(appPath, "firmware"); var csFiles = Directory.EnumerateFiles(sourceFolder); var csFilesContent = csFiles .Select(path => new FSTextFile() { Name = path, Content = File.ReadAllText(path) }) .ToList(); if (csFilesContent.Any()) { foreach (var cs in csFilesContent) { Console.WriteLine($"Found CS source: {cs.Name}"); } // translate source files var tx = new CSharp2CPPTranslator(); var source = new FSSnapshot(); source.Files.AddRange(csFilesContent); tx.Run(source); var firmwareSource = tx.Result; // create soc resource records var socGenerator = new SOCGenerator(); var socRecordsBuilder = new SOCRecordsBuilder(); var socRecords = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources); firmwareSource.Add(socGenerator.SOCImport(socRecords)); FileTools.CreateDirectoryRecursive(firmwareFolder); var m = new FSManager(firmwareFolder); m.SaveSnapshot(firmwareSource); } ModifyMakefile(); if (File.Exists(MakefileFile)) { var context = RISCVIntegration .DefaultContext(firmwareFolder) .WithMakeTarget("bin"); RISCVIntegrationClient.Make(context).Wait(); } if (File.Exists(FirmwareFile)) { var disassembler = new Disassembler(); File.WriteAllText(FirmwareAsmFile, disassembler.Disassemble(Instructions())); } return(File.Exists(FirmwareFile)); }