Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Convert test executions in bin/test.sh to ScalaTest using ModbatTestHarness #55

Open
cyrille-artho opened this issue May 21, 2019 · 5 comments

Comments

@cyrille-artho
Copy link
Owner

All the executions of the test cases can be converted from a list of command-line arguments to a list of strings and calls to testMain in ModbatTestHarness.

We still want to keep bin/test.sh for reference, but we also want a version that (1) does not execute any tests (similar to option -n) but (2) still checks all the outputs (which -n does not do).

First, we want to convert a couple of test cases that share similar settings, and then adapt a part of bin/test.sh as (for example) bin/diff.sh, to check the log/err outputs. Once that works, we will convert all 250+ tests.

@cyrille-artho
Copy link
Owner Author

cyrille-artho commented May 22, 2019

As a first step, please write a parser for the output of bin/test.sh -n. The parser should build a data structure for each of the 250+ test cases, and pretty-print the data in tab-separated format as follows:
Test number CLASSPATH [possibly empty] APP [scala ....jar] PARAM1 [-s=...] PARAM2 [-n=...] PARAM3... PARAMN

@cyrille-artho
Copy link
Owner Author

In the main loop of the parser, the logic would be as follows:
You always maintain one entry, with the necessary fields: classpath, appString, params[]

  1. When you see an empty line: print the current data (which is empty at the beginning), as tab-separated entries. After that, you clear all data.
  2. In the main parse loop, whenever you recognize a particular item, store it in that field (and extend the parameter list by one item if it is a parameter).

At the end, you have a program that processes one item at a time, and outputs all of them on the terminal. This allows us to visually inspect if most of the entries get parsed correctly. We can later redirect the output to a file and use that in Google sheets, or with grep -c to count items, etc.

AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 23, 2019
@cyrille-artho
Copy link
Owner Author

Please commit the script under a new branch, and commit + push it.
As a next step, I would like to work on two things:

  1. Get an overview of common parameters. For this, you can adapt the script from here: https://www.youtube.com/watch?time_continue=94&v=Pcyuaj5lCtA
    (Remove the hard-coded limit of "10", i.e., the parameter to most_common).
  2. We want to convert the output of your script to commands that run one scalatest unit test each. Example:
  "SetWeight2" should "pass with two transitions" in {
    val result = ModbatTestHarness.testMain(Array("-s=1", "-n=1", "--no-redirect-out", "-s", "modbat.test.SetWeight2"), ModbatTestHarness.setTestJar)
    result._1 should be(0)
    result._2.filter(_.contains("1 tests executed, 1 ok, 0 failed.")) should not be empty
    result._2.filter(_.contains("2 states covered (100 % out of 2),")) should not be empty
    result._2.filter(_.contains("2 transitions covered (100 % out of 2).")) should not be empty
    result._3 shouldBe empty
  }

For this, we need to

  1. find out how many class files to generate (based on what);
  2. know if we can (sometimes) find a way to create meaningful test names;
  3. check if we can import the right return code from bin/test.sh, or else fix that manually later.

We will also have to write the output to .log/.err files, and use an adapted version of bin/test.sh to diff them, later on.

AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 24, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 24, 2019
@cyrille-artho
Copy link
Owner Author

I am writing this in anticipation of the push/PR that will follow after the network connection problems are solved.

As a next step, focus on those tests that use modbat.jar as the application string (about 189 tests). Convert them to the unit test framework as used by, e.g., SetWeightTest. In the conversion, check result._1 and result._3, but not result._2 as of now.

Try to create the output such that all tests for the same class are collected in one class with a number of unit tests. You can use the class name plus a number as the test name.

cyrille-artho pushed a commit that referenced this issue May 28, 2019
* Python code and outputs results

* New python programs to know which arguments are the most common
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 29, 2019
cyrille-artho pushed a commit to AlexandreFournel/modbat that referenced this issue May 30, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 4, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 5, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 5, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 11, 2019
… and err files with easy name (Child1 for example). File Child modified: result3 should not be empty. InvalidMethod2 result3 should be empty, and same for Niosocket1
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 12, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 12, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 13, 2019
…ional argument which enables Test as ChooseTest, CounterModel, NioSocket, for example to copy their own dot file in another file with a different name (for example cov_10.dot)
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 14, 2019
…. Changes in ModbatTestHarness to implement way to compare eout and out files. It still doesn't work (two errors I don't know how to solve). But still work on it !
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 14, 2019
…d out of 2. Just the problem with value getLines is not a member of java.io.ByteArrayOutputStream is remaining
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 14, 2019
… skipped when the .out file doesn't exist
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 14, 2019
…the last commit are now solved. TODO : change the way to download the list of the .out. 170 tests failed after the compilation. Maybe the filtering doesn't work
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 18, 2019
… a way to replace regex in err and out files. I can't understand why the patterns are created each new test (whereas the function to create it is not inside a for loop). And We can't see if the pattern matchs or not... Strange because there are Console.println everywhere
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 18, 2019
… a way to replace regex in err and out files. And We can't see if the pattern matchs or not... Strange because there are Console.println everywhere
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 19, 2019
…code to have only 13 failed tests. However, the comparison is still false.
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 20, 2019
…g by [FINE] in out files, but it doesn't really work...
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 25, 2019
…comparison between former and new files works. I changed also the function replaceRegexInSentence using Maps. To conclue, for the err files, the grep -v removing the all sentence if regex matches has to be implement. At that time, we replace the sentence by an empty line... But does it impact the result of the comparison, I'm not sure...
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 26, 2019
…t files. Now, unfortunately, 75 succedeed tests..., comparison failed
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue Jun 26, 2019
cyrille-artho pushed a commit that referenced this issue Aug 1, 2020
* Python code and outputs results

* New python programs to know which arguments are the most common
cyrille-artho added a commit that referenced this issue Aug 10, 2020
…now be run inside a gradle unit test (#96)

* Issue #55: Convert tests to scalatest (#59)

* Refactoring in ConfigTest, migrated most tests from test.sh to unit tests.

* Refactored test harness into separate file.

* Minor adaptations to allow Modbat's main test harness to reuse the one from config.

* Refactoring and extension of test harness to be compatible for Modbat's main tests.

* Migrated some Modbat tests to new test harness that compares full output.

* Refactored model instance into its own class ModelInstance.

* Carried over instance refactoring to StatePair, StateSet, Transition.

* Carried over instance-based refactoring of Model, updated logs showing now a different number of method calls in stack trace.

* Ported instance-based refactoring to Action.

* Adapted test to use delayed initialization of random seed, so it works with the instance-based refactoring.

* Refactoring: pass config object to Dotify and use it instead of global Main.config.

* Refactoring: transition rewards use reference to config, avoiding global ref.

* Refactoring: TransitionCoverage now takes reference to Configuration.

* Minor refactoring: MBT now takes reference to Configuration in c'tor.

* Refactoring: Transition.ppTrans now takes autoLabels as extra param. to avoid using global config object.

* Refactored Path Graph classes to take reference to Configuration object instead of using global data.

* Refactored usage of MBT in TransitionCoverage so it is now passed as ref. to the two functions that need it.

* Refactored ModelInstance to take a reference to an MBT instance instead of using companion object, as far as possible at this point.

* PathVisualizer and subclasses now use MBT instead of Config reference so mbt.modelClass can be access; config is accessed indirectly

* Refactored MBT to be a class rather than using a companion object everywhere.

* ModelInstance now uses mbt.config instead of global Main.config.

* Using mbt.config instead of global config in Modbat.

* Made "firstInstance" and instance variable of MBT to simplify the code.

* Removed dead code.

* Using local (newly created) configuration object for each test.

* Use newly created configuration object for each run of main.

* Refactored Main to use a Modbat instance.

* Moved shutdown, wrapRun, runTest from companion object to class instance.

* Moved getRandomSeed to instance.

* Removed ref. to MBT instance from companion object.

* Modbat: Refactored call to "init" so it is now called from the constructor.

* Made "restoreChannels" an instance method, but using companion obj. vars due to remaining problem.

* Changed default out/err to System instead of Console, fixing strange test failurs.

* Refactored Modbat code as to be instance-based.

* Made output filter overridable by passing filter function; fixes output mismatch.

* Moved class loader config to c'tor of MBT.

* Better diagnostic info on exceptions.
	
* Changed harness to catch any type of exception/throwable.

* Made SourceInfo instance-based.

* Check both log/err first, then use assert, to store both mismatching results if present.

* Added an optional parameter to Main.run, such that the reference to the newly created Modbat instance can be passed back in case the shutdown handler has to be invoked manually after unit test failure.

* Refactored pendingTransitions into an instance variable of Model.

Co-authored-by: AlexandreFournel <39304175+AlexandreFournel@users.noreply.github.com>
@cyrille-artho
Copy link
Owner Author

This task can now be carried out for most unit tests; the only exceptions are tests producing multiple output files, for which the current test harness will have to be extended. Over 80 % of the existing tests can be ported now, thanks to PR #101.
This will be done over the coming weeks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant