Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mbe-tools
TTool
Commits
4e1444e2
Commit
4e1444e2
authored
1 year ago
by
Guillaume Blanc
Committed by
Guillaume Blanc
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Factorize code in AbstractTest
parent
6d1fc666
No related branches found
No related tags found
1 merge request
!485
Avatar security tests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ttool/src/test/java/test/AbstractTest.java
+73
-1
73 additions, 1 deletion
ttool/src/test/java/test/AbstractTest.java
ttool/src/test/java/ui/AvatarSecurityTests.java
+2
-60
2 additions, 60 deletions
ttool/src/test/java/ui/AvatarSecurityTests.java
with
75 additions
and
61 deletions
ttool/src/test/java/test/AbstractTest.java
+
73
−
1
View file @
4e1444e2
...
...
@@ -3,6 +3,7 @@ package test;
import
myutil.Conversion
;
import
myutil.FileException
;
import
myutil.FileUtils
;
import
myutil.TraceManager
;
import
org.w3c.dom.Document
;
import
org.xml.sax.SAXException
;
...
...
@@ -12,6 +13,8 @@ import javax.xml.parsers.ParserConfigurationException;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
java.util.stream.Stream
;
...
...
@@ -19,6 +22,7 @@ import static java.io.File.pathSeparator;
import
static
java
.
lang
.
System
.
getenv
;
import
static
java
.
nio
.
file
.
Files
.
isExecutable
;
import
static
java
.
util
.
regex
.
Pattern
.
quote
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
public
abstract
class
AbstractTest
{
...
...
@@ -29,12 +33,21 @@ public abstract class AbstractTest {
protected
static
String
INPUT_DIR
;
protected
static
String
EXPECTED_CODE_DIR
;
protected
static
String
ACTUAL_CODE_DIR
;
protected
static
final
String
PROVERIF_QUERY_PREFIX
=
"Query"
;
protected
static
final
String
PROVERIF_SUMMARY
=
"Verification summary:"
;
protected
static
String
getBaseResourcesDir
()
{
final
String
systemPropResDir
=
System
.
getProperty
(
"resources_dir"
);
if
(
systemPropResDir
==
null
)
{
return
"resources/test/"
;
String
isGradle
=
System
.
getProperty
(
"org.gradle.test.worker"
);
if
(
isGradle
==
null
)
{
return
"test/resources/"
;
}
else
{
return
"resources/test/"
;
}
}
return
systemPropResDir
;
...
...
@@ -199,4 +212,63 @@ public abstract class AbstractTest {
}
public
boolean
executeAndVerifyPvspec
(
String
pvspecPath
,
String
goldenPath
){
String
cmd
=
"proverif -in pitype "
+
pvspecPath
;
Process
process
;
BufferedReader
cmdOutput
;
try
{
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
cmdOutput
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
List
<
String
>
golden
=
generateGoldenList
(
goldenPath
);
String
outputLine
;
int
checked
=
0
;
boolean
summaryFound
=
false
;
while
((
outputLine
=
cmdOutput
.
readLine
())
!=
null
){
if
(
summaryFound
){
if
(
outputLine
.
startsWith
(
PROVERIF_QUERY_PREFIX
)){
if
(
golden
.
contains
(
outputLine
))
{
checked
+=
1
;
}
else
{
checked
=
-
1
;
break
;
}
}
}
else
{
if
(
outputLine
.
contains
(
PROVERIF_SUMMARY
)){
summaryFound
=
true
;
}
}
}
return
golden
.
size
()
==
checked
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
List
<
String
>
generateGoldenList
(
String
goldenPath
)
throws
IOException
{
BufferedReader
goldenFile
=
null
;
try
{
goldenFile
=
new
BufferedReader
(
new
FileReader
(
goldenPath
));
}
catch
(
FileNotFoundException
e
)
{
TraceManager
.
addDev
(
"File "
+
goldenPath
+
" not found"
);
throw
new
RuntimeException
(
e
);
}
List
<
String
>
goldenList
=
new
ArrayList
<>();
String
line
;
while
((
line
=
goldenFile
.
readLine
())
!=
null
){
if
(
line
.
startsWith
(
PROVERIF_QUERY_PREFIX
))
goldenList
.
add
(
line
);
}
return
goldenList
;
}
}
This diff is collapsed.
Click to expand it.
ttool/src/test/java/ui/AvatarSecurityTests.java
+
2
−
60
View file @
4e1444e2
...
...
@@ -25,8 +25,6 @@ public class AvatarSecurityTests extends AbstractUITest {
final
static
String
OUTPUT_FOLDER
=
"output/"
;
final
static
String
PVSPEC_SUFFIX
=
"_pvspec"
;
static
String
OUTPUT_DIR
;
static
final
String
PROVERIF_SUMMARY
=
"Verification summary:"
;
static
final
String
PROVERIF_QUERY_PREFIX
=
"Query"
;
final
static
String
[]
MODELS
=
{
...
...
@@ -35,11 +33,8 @@ public class AvatarSecurityTests extends AbstractUITest {
@BeforeClass
public
static
void
setUpBeforeClass
()
throws
Exception
{
String
test
=
System
.
getProperty
(
"org.gradle.test.worker"
);
String
baseResourcesDir
=
getBaseResourcesDir
();
if
(
test
==
null
){
baseResourcesDir
=
"test/resources/"
;
}
RESOURCES_DIR
=
baseResourcesDir
+
RES_FOLDER
;
INPUT_DIR
=
RESOURCES_DIR
+
INPUT_FOLDER
;
...
...
@@ -73,62 +68,9 @@ public class AvatarSecurityTests extends AbstractUITest {
boolean
pvspecGenerated
=
mainGUI
.
gtm
.
generateProVerifFromAVATAR
(
pvspecPath
,
0
,
true
,
true
);
assertTrue
(
pvspecGenerated
);
String
cmd
=
"proverif -in pitype "
+
pvspecPath
;
String
goldenPath
=
INPUT_DIR
+
model
+
GOLDEN_SUFFIX
;
Process
process
;
BufferedReader
cmdOutput
;
try
{
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
cmdOutput
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
List
<
String
>
golden
=
generateGoldenList
(
goldenPath
);
String
outputLine
;
int
checked
=
0
;
boolean
summaryFound
=
false
;
while
((
outputLine
=
cmdOutput
.
readLine
())
!=
null
){
if
(
summaryFound
){
if
(
outputLine
.
startsWith
(
PROVERIF_QUERY_PREFIX
)){
if
(
golden
.
contains
(
outputLine
))
{
checked
+=
1
;
}
else
{
checked
=
-
1
;
break
;
}
}
}
else
{
if
(
outputLine
.
contains
(
PROVERIF_SUMMARY
)){
summaryFound
=
true
;
}
}
}
assertEquals
(
golden
.
size
(),
checked
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
List
<
String
>
generateGoldenList
(
String
goldenPath
)
throws
IOException
{
BufferedReader
goldenFile
=
null
;
try
{
goldenFile
=
new
BufferedReader
(
new
FileReader
(
goldenPath
));
}
catch
(
FileNotFoundException
e
)
{
TraceManager
.
addDev
(
"File "
+
goldenPath
+
" not found"
);
throw
new
RuntimeException
(
e
);
}
List
<
String
>
goldenList
=
new
ArrayList
<>();
String
line
;
while
((
line
=
goldenFile
.
readLine
())
!=
null
){
if
(
line
.
startsWith
(
PROVERIF_QUERY_PREFIX
))
goldenList
.
add
(
line
);
}
return
goldenList
;
assertTrue
(
executeAndVerifyPvspec
(
pvspecPath
,
goldenPath
));
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment