Example #1
0
  public void testClass() {
    SVCorePlugin.getDefault().enableDebug(false);
    BundleUtils utils = new BundleUtils(SVCoreTestsPlugin.getDefault().getBundle());
    ByteArrayOutputStream bos;

    bos = utils.readBundleFile("/indent/class1.svh");

    String ref = bos.toString();
    StringBuilder sb = removeLeadingWS(ref);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(sb));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    StringBuilder result = new StringBuilder(indenter.indent(-1, -1));

    fLog.debug("Reference:\n" + ref);

    fLog.debug("===");
    fLog.debug("Result:\n" + result.toString());

    IndentComparator.compare("testClass", ref, result.toString());
  }
Example #2
0
  public void testSpecifySpecparam() {
    SVCorePlugin.getDefault().enableDebug(false);
    String content =
        "module m;\n"
            + "\n"
            + "specify\n"
            + "if (someSig[0] == 1'b0)\n"
            + "(CLK => Q[15])=(1.000, 1.000);\n"
            + "if (someSig[0] == 1'b0)\n"
            + "(CLK => Q[15])=(1.000, 1.000);\n"
            + "endspecify\n"
            + "endmodule\n";
    String expected =
        "module m;\n"
            + "\n"
            + "	specify\n"
            + "		if (someSig[0] == 1'b0)\n"
            + "			(CLK => Q[15])=(1.000, 1.000);\n"
            + "		if (someSig[0] == 1'b0)\n"
            + "			(CLK => Q[15])=(1.000, 1.000);\n"
            + "	endspecify\n"
            + "endmodule\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    fLog.debug("Result:");
    fLog.debug(result);
    IndentComparator.compare(getName(), expected, result);
  }
Example #3
0
  public void testEnumVar() {
    String testname = "testEnumVar";
    LogHandle log = LogFactory.getLogHandle(testname);
    String content =
        "module t;\n" + "enum {\n" + "A,\n" + "B\n" + "} e;\n" + "logic b;\n" + "endmodule\n";
    String expected =
        "module t;\n"
            + "	enum {\n"
            + "		A,\n"
            + "		B\n"
            + "	} e;\n"
            + "	logic b;\n"
            + "endmodule\n";
    log.debug("--> " + testname);

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare(testname, expected, result);
    log.debug("<-- " + testname);

    LogFactory.removeLogHandle(log);
  }
Example #4
0
  public void testTypedefNonStructUnion() {
    String testname = "testTypedefNonStructUnion";
    LogHandle log = LogFactory.getLogHandle(testname);
    SVCorePlugin.getDefault().enableDebug(false);
    String content =
        "module t;\n"
            + "typedef int unsigned uint32_t;\n"
            + "typedef short unsigned uint16_t;\n"
            + "uint32_t foo;\n"
            + "endmodule\n";
    String expected =
        "module t;\n"
            + "	typedef int unsigned uint32_t;\n"
            + "	typedef short unsigned uint16_t;\n"
            + "	uint32_t foo;\n"
            + "endmodule\n";
    log.debug("--> " + testname);

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare(testname, expected, result);
    log.debug("<-- " + testname);

    LogFactory.removeLogHandle(log);
  }
Example #5
0
  public void testGenerate() {
    LogHandle log = LogFactory.getLogHandle("testGenerate");
    String content =
        "module t;\n"
            + "parameter a = 0;\n"
            + "generate\n"
            + "if(a == 0) begin\n"
            + "// ...\n"
            + "end\n"
            + "if(a == 1) begin\n"
            + "// ...\n"
            + "end\n"
            + "endgenerate\n"
            + "generate\n"
            + "begin:bob\n"
            + "if(a == 0) begin\n"
            + "// ...\n"
            + "end\n"
            + "if(a == 1) begin\n"
            + "// ...\n"
            + "end\n"
            + "end\n"
            + "endgenerate\n"
            + "endmodule\n";
    String expected =
        "module t;\n"
            + "	parameter a = 0;\n"
            + "	generate\n"
            + "		if(a == 0) begin\n"
            + "			// ...\n"
            + "		end\n"
            + "		if(a == 1) begin\n"
            + "			// ...\n"
            + "		end\n"
            + "	endgenerate\n"
            + "	generate\n"
            + "	begin:bob\n"
            + "		if(a == 0) begin\n"
            + "			// ...\n"
            + "		end\n"
            + "		if(a == 1) begin\n"
            + "			// ...\n"
            + "		end\n"
            + "	end\n"
            + "	endgenerate\n"
            + "endmodule\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testGenerate", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #6
0
  public void testBasicCoverpoint() {
    SVCorePlugin.getDefault().enableDebug(false);
    String content =
        "class c1;\n"
            + "\n"
            + "covergroup cg1;\n"
            + "cp : coverpoint a {\n"
            + "bins ab[] = {1, 2, 3, 4};\n"
            + "}\n"
            + "endgroup\n"
            + "endclass\n";
    String expected =
        "class c1;\n"
            + "\n"
            + "	covergroup cg1;\n"
            + "		cp : coverpoint a {\n"
            + "			bins ab[] = {1, 2, 3, 4};\n"
            + "		}\n"
            + "	endgroup\n"
            + "endclass\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    fLog.debug("Result:");
    fLog.debug(result);
    IndentComparator.compare(getName(), expected, result);
  }
Example #7
0
  public void testBasicModuleWire() {
    LogHandle log = LogFactory.getLogHandle("testBasicModuleWire");
    String content =
        "module top;\n"
            + "// comment1\n"
            + "logic a;\n"
            + "logic b;\n"
            + "// comment2\n"
            + "endmodule\n";
    String expected =
        "module top;\n"
            + "	// comment1\n"
            + "	logic a;\n"
            + "	logic b;\n"
            + "	// comment2\n"
            + "endmodule\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testBasicModuleWire", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #8
0
  public void testFunctionFirstItemComment() {
    String ref =
        "module foo;\n"
            + "	\n"
            + "	function automatic void foobar_f();\n"
            + "		// this is a comment\n"
            + "	endfunction\n"
            + "	a = 5;\n"
            + "endmodule\n";

    SVCorePlugin.getDefault().enableDebug(false);
    LogHandle log = LogFactory.getLogHandle("testFunctionFirstItemComment");

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, "testFunctionFirstItemComment", ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #9
0
  public void testFunctionComment() {
    String ref =
        "class my_class;\n"
            + "\n"
            + "	/**\n"
            + "	 * my_func\n"
            + "	 *\n"
            + "	 */\n"
            + "	function void foobar;\n"
            + "\n"
            + "	endfunction\n"
            + "\n"
            + "endclass\n";

    LogHandle log = LogFactory.getLogHandle("testFunctionComment");
    SVCorePlugin.getDefault().enableDebug(false);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:");
    log.debug(result);
    log.debug("====");

    IndentComparator.compare(log, "testFunctionComment", ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #10
0
  public void testMultiBlankLine() {
    LogHandle log = LogFactory.getLogHandle("testMultiBlankLine");
    String ref =
        "class my_component1 extends ovm_component;\n"
            + "	\n"
            + "	\n"
            + "	function new(string name, ovm_component parent);\n"
            + "		super.new(name, parent);\n"
            + "	endfunction\n"
            + "	\n"
            + "	\n"
            + "endclass\n";

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:");
    log.debug(result);
    log.debug("====");

    IndentComparator.compare(log, "testMultiBlankLine", ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #11
0
  public void testInitialBlock() {
    LogHandle log = LogFactory.getLogHandle("testInitialBlock");
    String content =
        "module t;\n" + "logic a;\n" + "initial begin\n" + "a = 5;\n" + "end\n" + "endmodule\n";
    String expected =
        "module t;\n"
            + "	logic a;\n"
            + "	initial begin\n"
            + "		a = 5;\n"
            + "	end\n"
            + "endmodule\n";
    log.debug("--> testInitialBlock");

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testInitialBlock", expected, result);
    log.debug("<-- testInitialBlock");

    LogFactory.removeLogHandle(log);
  }
Example #12
0
  public void testModule() {
    BundleUtils utils = new BundleUtils(SVCoreTestsPlugin.getDefault().getBundle());
    ByteArrayOutputStream bos;

    bos = utils.readBundleFile("/indent/module.svh");

    String expected = bos.toString();
    StringBuilder sb = removeLeadingWS(expected);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(sb));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();
    IndentComparator.compare("testModule", expected, result);

    /*
    StringBuilder result = new StringBuilder(indenter.indent(-1, -1));
    StringBuilder reference = new StringBuilder(ref);

    String ref_line, ind_line;
    int err_cnt = 0;
    int pass_cnt = 0;

    do {
    	ref_line = readLine(reference);
    	ind_line = readLine(result);

    	if (ref_line != null && ind_line != null) {
    		if (ref_line.equals(ind_line)) {
    			log.debug("[OK ]:" + ref_line);
    			pass_cnt++;
    		} else {
    			log.debug("[ERR]:" + ref_line);
    			log.debug("[   ]:" + ind_line);
    			err_cnt++;
    		}
    	}
    } while (ref_line != null && ind_line != null);

    assertNull("Checking that output not truncated", ref_line);
    assertNull("Checking for no excess output", ind_line);

    assertEquals("Expect no errors", 0, err_cnt);
    assertTrue("Check accomplished work", (pass_cnt != 0));
     */
  }
Example #13
0
  public void testIndentPostSingleComment() {
    LogHandle log = LogFactory.getLogHandle("testIndentPostSingleComment");
    String content =
        "class foo;\n"
            + // 1
            "//comment1\n"
            + "function void my_func();\n"
            + // 2
            "if (foobar) begin\n"
            + // 3
            "end else begin\n"
            + // 4
            "// comment block\n"
            + // 5
            "a.b = 5;\n"
            + // 6
            "end\n"
            + // 7
            "endfunction\n"
            + // 8
            "//comment2\n"
            + "endclass\n" // 9
        ;
    String expected =
        "class foo;\n"
            + "	//comment1\n"
            + "	function void my_func();\n"
            + "		if (foobar) begin\n"
            + "		end else begin\n"
            + "			// comment block\n"
            + "			a.b = 5;\n"
            + "		end\n"
            + "	endfunction\n"
            + "	//comment2\n"
            + "endclass\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testIndentPostSingleComment", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #14
0
  public static void runTest(String name, LogHandle log, String doc) {
    StringBuilder sb = removeLeadingWS(doc);
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(sb));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    //		indenter.setAdaptiveIndent(true);
    //		indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + doc);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, name, doc, result);
  }
Example #15
0
  public void testBasicClass() {
    LogHandle log = LogFactory.getLogHandle("testBasicClass");
    String content =
        "\n"
            + "class class1 #(type T=int);\n"
            + "\n"
            + "virtual interface some_if the_if;\n"
            + "\n"
            + "function new();\n"
            + "if (foo)\n"
            + "foo = 5;\n"
            + "else if (foo2) begin\n"
            + "foo = 6;\n"
            + "end\n"
            + "endfunction\n"
            + "endclass\n";
    String expected =
        "\n"
            + "class class1 #(type T=int);\n"
            + "\n"
            + "	virtual interface some_if the_if;\n"
            + "\n"
            + "	function new();\n"
            + "		if (foo)\n"
            + "			foo = 5;\n"
            + "		else if (foo2) begin\n"
            + "			foo = 6;\n"
            + "		end\n"
            + "	endfunction\n"
            + "endclass\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testBasicClass", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #16
0
  public void testTypedefUnion() {
    String testname = "testTypedefUnion";
    LogHandle log = LogFactory.getLogHandle(testname);
    String content =
        "module t;\n"
            + "typedef union {\n"
            + "//comment1\n"
            + "int a;\n"
            + "//comment2\n"
            + "int b;\n"
            + "} foo_t;\n"
            + "//comment3\n"
            + "foo_t b;\n"
            + "endmodule\n";
    String expected =
        "module t;\n"
            + "	typedef union {\n"
            + "		//comment1\n"
            + "		int a;\n"
            + "		//comment2\n"
            + "		int b;\n"
            + "	} foo_t;\n"
            + "	//comment3\n"
            + "	foo_t b;\n"
            + "endmodule\n";
    log.debug("--> " + testname);

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare(testname, expected, result);
    log.debug("<-- " + testname);

    LogFactory.removeLogHandle(log);
  }
Example #17
0
  public void testEmptyCaseStmt() throws Exception {
    LogHandle log = LogFactory.getLogHandle("testEmptyCaseStmt");
    String content =
        "module t;\n"
            + "logic a;\n"
            + "always @ (a) begin\n"
            + "case(a)\n"
            + "endcase\n"
            + "end\n"
            + "endmodule\n";
    String expected =
        "module t;\n"
            + "	logic a;\n"
            + "	always @ (a) begin\n"
            + "		case(a)\n"
            + "		endcase\n"
            + "	end\n"
            + "endmodule\n";

    SVCorePlugin.getDefault().enableDebug(false);
    log.debug("--> testEmptyCaseStmt()");
    try {
      SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

      ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
      indenter.init(scanner);
      indenter.setTestMode(true);

      String result = indenter.indent();

      log.debug("Result:");
      log.debug(result);
      IndentComparator.compare("testEmptyCaseStmt", expected, result);
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    } finally {
      log.debug("<-- testEmptyCaseStmt()");
    }
    LogFactory.removeLogHandle(log);
  }
Example #18
0
  public void testForever() {
    String testname = "testForever";
    String ref =
        "module foo ();\n"
            + "	initial begin\n"
            + "		forever #1\n"
            + "		begin\n"
            + "			a=b;\n"
            + "		end\n"
            + "	end\n"
            + "endmodule\n";

    SVCorePlugin.getDefault().enableDebug(false);
    LogHandle log = LogFactory.getLogHandle(testname);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, testname, ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #19
0
  public void testEmptyForkJoin() {
    String testname = "testEmptyForkJoin";
    String ref =
        "class foo;\n" + "	task bar();\n" + "		fork\n" + "		join\n" + "	endtask\n" + "endclass\n";

    SVCorePlugin.getDefault().enableDebug(false);
    LogHandle log = LogFactory.getLogHandle(testname);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, testname, ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #20
0
  public void testRandomizeWith() {
    String ref =
        "class foo;\n"
            + "	virtual function void build_phase(uvm_phase phase);\n"
            + "		this.randomize(random_int) with\n"
            + "			{ random_int > 0;\n"
            + "				random_int<100;\n"
            + "			};\n"
            + "		this.randomize(random_int) with\n"
            + "			{ random_int > 0;\n"
            + "				random_int<100;\n"
            + "			};\n"
            + "	endfunction\n"
            + "endclass\n";

    SVCorePlugin.getDefault().enableDebug(false);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    fLog.debug("Ref:\n" + ref);
    fLog.debug("====");
    fLog.debug("Result:\n" + result);
    fLog.debug("====");

    IndentComparator.compare(fLog, getName(), ref, result);
  }
Example #21
0
  public void testNoBlockIf() {
    String content =
        "class class1;\n"
            + "\n"
            + "function new();\n"
            + "if (foo)\n"
            + "$display(\"Hello\");\n"
            + "else\n"
            + "$display(\"Goodbye\");\n"
            + "foo = 6;\n"
            + "endfunction\n"
            + "endclass\n";
    String expected =
        "class class1;\n"
            + "\n"
            + "	function new();\n"
            + "		if (foo)\n"
            + "			$display(\"Hello\");\n"
            + "		else\n"
            + "			$display(\"Goodbye\");\n"
            + "		foo = 6;\n"
            + "	endfunction\n"
            + "endclass\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    fLog.debug("Result:");
    fLog.debug(result);
    IndentComparator.compare(getName(), expected, result);
  }
Example #22
0
  public void testIfInFunction() {
    String ref =
        "class xbus_bus_monitor;\n"
            + // 1
            "\n"
            + // 2
            "		function void ignored();\n"
            + // 3
            "		endfunction\n"
            + // 4
            "\n"
            + // 5
            "		// perform_transfer_coverage\n"
            + // 6
            "		function void perform_transfer_coverage();\n"
            + "			if (trans_collected.read_write != NOP) begin\n"
            + "				-> cov_transaction;\n"
            + "				for (int unsigned i = 0; i < trans_collected.size; i++) begin\n"
            + "					addr = trans_collected.addr + i;\n"
            + "					data = trans_collected.data[i];\n"
            + "					wait_state = trans_collected.wait_state[i];\n"
            + "					-> cov_transaction_beat;\n"
            + "				end\n"
            + "			end\n"
            + "		endfunction : perform_transfer_coverage\n"
            + "\n"
            + "endclass : xbus_bus_monitor\n";

    SVCorePlugin.getDefault().enableDebug(false);
    LogHandle log = LogFactory.getLogHandle("testIfInFunction");

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, "testIfInFunction", ref, result);
    LogFactory.removeLogHandle(log);
  }
Example #23
0
  public void testPoundDelay() {
    String ref =
        "module m ();\n"
            + "	initial begin\n"
            + "		#1110;\n"
            + "		a = b;\n"
            + "		#1110 a = b;\n"
            + "		#1111ns	// No ;\n"
            + "			a = b;\n"
            + "		#1113fs	// No ;\n"
            + "			// comment \n"
            + "			for (i=0; i<5; i++)\n"
            + "			begin\n"
            + "				a = b;\n"
            + "			end\n"
            + "		#112ps;	// with ;\n"
            + "		if (a == b)\n"
            + "		begin\n"
            + "			a = b;\n"
            + "		end\n"
            + "	end\n"
            + "endmodule\n";

    SVCorePlugin.getDefault().enableDebug(false);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    fLog.debug("Ref:\n" + ref);
    fLog.debug("====");
    fLog.debug("Result:\n" + result);
    fLog.debug("====");

    IndentComparator.compare(fLog, getName(), ref, result);
  }
Example #24
0
  public void testBasicModuleComment() {
    LogHandle log = LogFactory.getLogHandle("testBasicModuleComment");
    String content =
        "module t; // Comment.\n"
            + "logic a;\n"
            + "logic b;\n"
            + "\n"
            + "//comment1\n"
            + "assign a = b;\n"
            + "\n"
            + "//comment2\n"
            + "assign a = \n"
            + "//comment2.1\n"
            + "b;\n"
            + "//comment2.2\n"
            + "assign a = (\n"
            + "//comment2.2.1\n"
            + "b +\n"
            + "//comment2.2.2\n"
            + "(\n"
            + "//comment2.2.3\n"
            + "1 + 2\n"
            + "//comment2.2.4\n"
            + ")\n"
            + "//comment2.2.5\n"
            + ");\n"
            + "//comment3\n"
            + "submod sm1 (.a(a),\n"
            + "//comment4\n"
            + ".b(b),\n"
            + "//comment5\n"
            + ".c(\n"
            + "//comment5.1\n"
            + "c\n"
            + "//comment5.2\n"
            + "),\n"
            + "//comment6\n"
            + ".d(\n"
            + "//comment6.1\n"
            + "(\n"
            + "//comment6.2\n"
            + "(\n"
            + "//comment6.3\n"
            + "d+1\n"
            + "//comment6.4\n"
            + ")\n"
            + "//comment6.5\n"
            + ")\n"
            + "//comment6.6\n"
            + ")\n"
            + ");\n"
            + "//comment7\n"
            + "endmodule\n";
    String expected =
        "module t; // Comment.\n"
            + "	logic a;\n"
            + "	logic b;\n"
            + "\n"
            + "	//comment1\n"
            + "	assign a = b;\n"
            + "\n"
            + "	//comment2\n"
            + "	assign a = \n"
            + "		//comment2.1\n"
            + "		b;\n"
            + "	//comment2.2\n"
            + "	assign a = (\n"
            + "			//comment2.2.1\n"
            + "			b +\n"
            + "			//comment2.2.2\n"
            + "			(\n"
            + "				//comment2.2.3\n"
            + "				1 + 2\n"
            + "				//comment2.2.4\n"
            + "			)\n"
            + "			//comment2.2.5\n"
            + "		);\n"
            + "	//comment3\n"
            + "	submod sm1 (.a(a),\n"
            + "			//comment4\n"
            + "			.b(b),\n"
            + "			//comment5\n"
            + "			.c(\n"
            + "				//comment5.1\n"
            + "				c\n"
            + "				//comment5.2\n"
            + "			),\n"
            + "			//comment6\n"
            + "			.d(\n"
            + "				//comment6.1\n"
            + "				(\n"
            + "					//comment6.2\n"
            + "					(\n"
            + "						//comment6.3\n"
            + "						d+1\n"
            + "						//comment6.4\n"
            + "					)\n"
            + "					//comment6.5\n"
            + "				)\n"
            + "				//comment6.6\n"
            + "			)\n"
            + "		);\n"
            + "	//comment7\n"
            + "endmodule\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testBasicModuleComment", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #25
0
  public void testAssertStmt() {
    LogHandle log = LogFactory.getLogHandle("testAssertStmt");
    String content =
        "\n"
            + "module t; // Comment.\n"
            + "task t();\n"
            + "assert (this.foo.randomize ()); // Single line assertion\n"
            + "assert (this.foo.randomize ())  // assert-else\n"
            + "else \n"
            + "$display (\"Fail\");\n"
            + "assert (a==1) // assert pass message fail message\n"
            + "begin\n"
            + "$display (\"Pass\");\n"
            + "end\n"
            + "else\n"
            + "$display (\"Fail\");\n"
            + "if (1)	begin\n"
            + "thing = 1;\n"
            + "end\n"
            + "else\n"
            + "begin\n"
            + "thing = 2;\n"
            + "end\n"
            + "endtask\n"
            + "//comment1\n"
            + "assign a = b;\n"
            + "endmodule\n";
    String expected =
        "\n"
            + "module t; // Comment.\n"
            + "	task t();\n"
            + "		assert (this.foo.randomize ()); // Single line assertion\n"
            + "		assert (this.foo.randomize ())  // assert-else\n"
            + "		else \n"
            + "			$display (\"Fail\");\n"
            + "		assert (a==1) // assert pass message fail message\n"
            + "		begin\n"
            + "			$display (\"Pass\");\n"
            + "		end\n"
            + "		else\n"
            + "			$display (\"Fail\");\n"
            + "		if (1)	begin\n"
            + "			thing = 1;\n"
            + "		end\n"
            + "		else\n"
            + "		begin\n"
            + "			thing = 2;\n"
            + "		end\n"
            + "	endtask\n"
            + "	//comment1\n"
            + "	assign a = b;\n"
            + "endmodule\n";

    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(content));

    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    String result = indenter.indent();

    log.debug("Result:");
    log.debug(result);
    IndentComparator.compare("testAssertStmt", expected, result);
    LogFactory.removeLogHandle(log);
  }
Example #26
0
  public void testPreProcIndent() {
    String testname = "testPreProcIndent";
    String ref =
        "package foo;\n"
            + "	import pkg_1::*;\n"
            + "	`include \"file1.svh\"\n"
            + "	`include \"file2.svh\"\n"
            + "	`include \"file3.svh\"\n"
            + "endpackage\n"
            + "\n"
            + "`ifndef INCLUDED_my_component1_svhn\n"
            + "	module m ();\n"
            + "		`ifdef ASDF // comment\n"
            + "			// comment\n"
            + "			assign a = b;\n"
            + "		`else\n"
            + "			// comment\n"
            + "			assign c=d;\n"
            + "	\n"
            + "		`endif\n"
            + "		`ifdef ASDF assign a = b; `else assign b = c; `endif\n"
            + "		`ifdef ASDF assign a = b; /* comment */ `else assign b = c; /* comment */ `endif /* comment */ // comment\n"
            + "		initial\n"
            + "		begin\n"
            + "			`ifdef ASDF\n"
            + "				// comment\n"
            + "				a = b;\n"
            + "				a = b;\n"
            + "			`endif\n"
            + "			\n"
            + "		end\n"
            + "		always @*\n"
            + "		begin\n"
            + "			`ifdef ASDF\n"
            + "				// comment\n"
            + "				a = b;\n"
            + "				a = b;\n"
            + "			`endif\n"
            + "			\n"
            + "		end\n"
            + "	endmodule\n"
            + "`endif				// comment\n"
            + "// comment\n";

    SVCorePlugin.getDefault().enableDebug(false);
    LogHandle log = LogFactory.getLogHandle(testname);

    // Run the indenter over the reference source
    SVIndentScanner scanner = new SVIndentScanner(new StringTextScanner(ref));
    ISVIndenter indenter = SVCorePlugin.getDefault().createIndenter();
    indenter.init(scanner);
    indenter.setTestMode(true);

    indenter.setAdaptiveIndent(true);
    indenter.setAdaptiveIndentEnd(5);
    String result = indenter.indent(-1, -1);

    log.debug("Ref:\n" + ref);
    log.debug("====");
    log.debug("Result:\n" + result);
    log.debug("====");

    IndentComparator.compare(log, testname, ref, result);
    LogFactory.removeLogHandle(log);
  }