Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft approach for running tutorials in JUnit tests #773

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Draft approach for running tutorials in JUnit tests
Signed-off-by: Chris Lavin <[email protected]>
  • Loading branch information
clavin-xlnx committed Jul 27, 2023
commit 076c52110927c4d9dc4901f425b96a9fb22af95a
47 changes: 47 additions & 0 deletions test/shared/com/xilinx/rapidwright/support/Tutorial.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
83 changes: 83 additions & 0 deletions test/shared/com/xilinx/rapidwright/support/TutorialSupport.java
Original file line number Diff line number Diff line change
@@ -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<String> runTutorialVivadoCommands(Path tmpDir, Tutorial name, int... lineNumbers) {
List<String> 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<String> runTutorialCommands(Path tmpDir, Tutorial name, int... lineNumbers) {
List<String> commands = getTutorialCommands(tmpDir, name, lineNumbers);
for (String command : commands) {
FileTools.runCommand(command, true, null, tmpDir.toFile());
}
return commands;
}

public static List<String> 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<String> tmpFileLines = FileTools.getLinesFromTextFile(tmpFile.toString());
List<String> 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;
}
}
68 changes: 68 additions & 0 deletions test/src/com/xilinx/rapidwright/tutorials/RWRouteTutorials.java
Original file line number Diff line number Diff line change
@@ -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<String> cmds = TutorialSupport.runTutorialCommands(dir, name, lineNumbers);
if (FileTools.isVivadoOnPath()) {
Path outputDCP = dir.resolve(cmds.get(2).split(" ")[2]);
Assertions.assertTrue(VivadoTools.reportRouteStatus(outputDCP).isFullyRouted());
}
}
}
Original file line number Diff line number Diff line change
@@ -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
);
}
}
39 changes: 39 additions & 0 deletions test/src/com/xilinx/rapidwright/tutorials/SLRCrosser.java
Original file line number Diff line number Diff line change
@@ -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);
}
}