diff --git a/test/shared/com/xilinx/rapidwright/support/Tutorial.java b/test/shared/com/xilinx/rapidwright/support/Tutorial.java new file mode 100644 index 000000000..f64020263 --- /dev/null +++ b/test/shared/com/xilinx/rapidwright/support/Tutorial.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Author: Chris Lavin, AMD Research and Advanced Development. + * + * This file is part of RapidWright. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xilinx.rapidwright.support; + +public enum Tutorial { + + RWROUTE_TIMING_DRIVEN("RWRoute_timing_driven_routing"), + RWROUTE_WIRELENGTH_DRIVEN("RWRoute_wirelength_driven_routing"), + RWROUTE_PARTIAL("RWRoute_partial_routing"), + REPORT_TIMING_EXAMPLE("ReportTimingExample"), + REUSING_TIMING_CLOSED_LOGIC_AS_A_SHELL("ReusingTimingClosedLogicAsAShell"), + SLR_CROSSER_DCP_CREATOR("SLR_Crosser_DCP_Creator_Tutorial"), + PREIMPLEMENTED_MODULES_PART_I("PreImplemented_Modules_Part_I"), + PREIMPLEMENTED_MODULES_PART_II("PreImplemented_Modules_Part_II"), + CREATE_AND_USE_AN_SLR_BRIDGE("Create_and_Use_an_SLR_Bridge"), + ; + + private String filename; + + private Tutorial(String filename) { + this.filename = filename; + } + + public String getFileName() { + return filename; + } +} diff --git a/test/shared/com/xilinx/rapidwright/support/TutorialSupport.java b/test/shared/com/xilinx/rapidwright/support/TutorialSupport.java new file mode 100644 index 000000000..8e3d2919f --- /dev/null +++ b/test/shared/com/xilinx/rapidwright/support/TutorialSupport.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Author: Chris Lavin, AMD Research and Advanced Development. + * + * This file is part of RapidWright. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xilinx.rapidwright.support; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import com.xilinx.rapidwright.util.FileTools; +import com.xilinx.rapidwright.util.VivadoTools; + +public class TutorialSupport { + + public static final String TUTORIAL_FOLDER = "http://www.rapidwright.io/docs/_sources/"; + + public static final String RST_SRC_SUFFIX = ".rst.txt"; + + public static List runTutorialVivadoCommands(Path tmpDir, Tutorial name, int... lineNumbers) { + List commands = getTutorialCommands(tmpDir, name, lineNumbers); + + // Run 'rapidwright' commands in vivado to avoid breaking the context flow + // and join initial 'vivado -source' commands so they are contiguous + for (int i = 0; i < commands.size(); i++) { + String command = commands.get(i); + if (command.startsWith("rapidwright ")) { + commands.set(i, "exec " + command); + } else if (command.startsWith("vivado -source ")) { + commands.set(i, command.replace("vivado -", "")); + } else if (command.equals("report_route_status")) { + commands.set(i, "if {![report_route_status -boolean_check ROUTED_FULLY]} { error {} }"); + } + } + + Path tmpTcl = tmpDir.resolve("tmp.tcl"); + FileTools.writeLinesToTextFile(commands, tmpTcl.toString()); + + VivadoTools.runTcl(tmpDir.resolve("output.log"), tmpTcl, true, null, tmpDir.toFile()); + return commands; + } + + public static List runTutorialCommands(Path tmpDir, Tutorial name, int... lineNumbers) { + List commands = getTutorialCommands(tmpDir, name, lineNumbers); + for (String command : commands) { + FileTools.runCommand(command, true, null, tmpDir.toFile()); + } + return commands; + } + + public static List getTutorialCommands(Path tmpDir, Tutorial name, int[] lineNumbers) { + Path tmpFile = tmpDir.resolve(name + RST_SRC_SUFFIX); + FileTools.runCommand("wget " + getTutorialSourceURL(name) + " -O " + tmpFile.toString(), true); + List tmpFileLines = FileTools.getLinesFromTextFile(tmpFile.toString()); + List lines = new ArrayList<>(); + for (int lineNumber : lineNumbers) { + lines.add(tmpFileLines.get(lineNumber - 1).trim()); + } + return lines; + } + + public static String getTutorialSourceURL(Tutorial name) { + return TUTORIAL_FOLDER + name.getFileName() + RST_SRC_SUFFIX; + } +} diff --git a/test/src/com/xilinx/rapidwright/tutorials/RWRouteTutorials.java b/test/src/com/xilinx/rapidwright/tutorials/RWRouteTutorials.java new file mode 100644 index 000000000..a4e67e419 --- /dev/null +++ b/test/src/com/xilinx/rapidwright/tutorials/RWRouteTutorials.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Author: Chris Lavin, AMD Research and Advanced Development. + * + * This file is part of RapidWright. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xilinx.rapidwright.tutorials; + +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.xilinx.rapidwright.support.LargeTest; +import com.xilinx.rapidwright.support.Tutorial; +import com.xilinx.rapidwright.support.TutorialSupport; +import com.xilinx.rapidwright.util.FileTools; +import com.xilinx.rapidwright.util.VivadoTools; + +public class RWRouteTutorials { + + @Test + @LargeTest(max_memory_gb = 8) + public void testRWRouteTimingDrivenRouting(@TempDir Path dir) { + testRWRouteTutorials(dir, Tutorial.RWROUTE_TIMING_DRIVEN, 15, 21); + } + + @Test + @LargeTest(max_memory_gb = 8) + public void testRWRouteWirelengthDrivenRouting(@TempDir Path dir) { + testRWRouteTutorials(dir, Tutorial.RWROUTE_WIRELENGTH_DRIVEN, 15, 21); + } + + @Test + @LargeTest(max_memory_gb = 8) + public void testRWRoutePartialRouting(@TempDir Path dir) { + testRWRouteTutorials(dir, Tutorial.RWROUTE_PARTIAL, 15, 22); + } + + private void testRWRouteTutorials(Path dir, Tutorial name, int... lineNumbers) { + long maxMemoryNeeded = 1024L * 1024L * 1024L * 8L; + Assumptions.assumeTrue(Runtime.getRuntime().maxMemory() >= maxMemoryNeeded); + List cmds = TutorialSupport.runTutorialCommands(dir, name, lineNumbers); + if (FileTools.isVivadoOnPath()) { + Path outputDCP = dir.resolve(cmds.get(2).split(" ")[2]); + Assertions.assertTrue(VivadoTools.reportRouteStatus(outputDCP).isFullyRouted()); + } + } +} diff --git a/test/src/com/xilinx/rapidwright/tutorials/ReuseTimingClosedLogicAsAShell.java b/test/src/com/xilinx/rapidwright/tutorials/ReuseTimingClosedLogicAsAShell.java new file mode 100644 index 000000000..0270de204 --- /dev/null +++ b/test/src/com/xilinx/rapidwright/tutorials/ReuseTimingClosedLogicAsAShell.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Author: Chris Lavin, AMD Research and Advanced Development. + * + * This file is part of RapidWright. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xilinx.rapidwright.tutorials; + +import java.nio.file.Path; + +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.xilinx.rapidwright.support.Tutorial; +import com.xilinx.rapidwright.support.TutorialSupport; +import com.xilinx.rapidwright.util.FileTools; + +/** + * Runs the "Reuse Timing-closed Logic As A Shell" Tutorial as a test + */ +public class ReuseTimingClosedLogicAsAShell { + + /** + * This test runs the same commands as found in + * 'RapidWrightInt/sphinx/ReusingTimingClosedLogicAsAShell.rst' + * + * @param path Temporary path to run the tutorial + */ + @Test + public void testReuseTimingClosedLogicAsAShell(@TempDir Path path) { + Assumptions.assumeTrue(FileTools.isVivadoOnPath()); + + TutorialSupport.runTutorialCommands(path, Tutorial.REUSING_TIMING_CLOSED_LOGIC_AS_A_SHELL, + 118, 119, 120); + + TutorialSupport.runTutorialVivadoCommands(path.resolve("kcu105"), + Tutorial.REUSING_TIMING_CLOSED_LOGIC_AS_A_SHELL, + 121, 145, 146, 147, 148, 175, 194, 195, 261, 274, 281, 282, 283, 284 + ); + } +} diff --git a/test/src/com/xilinx/rapidwright/tutorials/SLRCrosser.java b/test/src/com/xilinx/rapidwright/tutorials/SLRCrosser.java new file mode 100644 index 000000000..4123ad18e --- /dev/null +++ b/test/src/com/xilinx/rapidwright/tutorials/SLRCrosser.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Author: Chris Lavin, AMD Research and Advanced Development. + * + * This file is part of RapidWright. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xilinx.rapidwright.tutorials; + +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.xilinx.rapidwright.support.Tutorial; +import com.xilinx.rapidwright.support.TutorialSupport; + +public class SLRCrosser { + + @Test + public void testSLRCrosserDCPCreator(@TempDir Path path) { + TutorialSupport.runTutorialCommands(path, Tutorial.SLR_CROSSER_DCP_CREATOR, 32, 75); + } +}