Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
df9737a4
Commit
df9737a4
authored
Jul 10, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the watermarker test
parent
5809f290
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
172 additions
and
2 deletions
+172
-2
test1.wast
example/test1.wast
+11
-0
FunctionOrderingWatermarker.cpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
+2
-0
FunctionOrderingWatermarker.hpp
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
+3
-1
snpi.cpp
src/snpi.cpp
+1
-0
CMakeLists.txt
test/CMakeLists.txt
+2
-1
test_BitStreamReader.cpp
test/kyut/test_BitStreamReader.cpp
+65
-0
test_FunctionOrderingWatermarker.cpp
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
+88
-0
No files found.
example/test1.wast
0 → 100644
View file @
df9737a4
(module
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f3" (func $f3))
(import "env" "g1" (func $g1))
(import "env" "g2" (func $g2))
(import "env" "g3" (func $g3))
(func $f1 (result i32) (i32.const 1))
(func $f2 (result i32) (i32.const 2))
(func $f3 (result i32) (i32.const 3))
)
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
View file @
df9737a4
...
...
@@ -5,6 +5,8 @@
#include <cassert>
#include <iostream>
#include "../BitStreamReader.hpp"
namespace
kyut
::
watermarker
{
namespace
{
/**
...
...
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
View file @
df9737a4
...
...
@@ -3,7 +3,9 @@
#include <wasm.h>
#include "../BitStreamReader.hpp"
namespace
kyut
{
class
BitStreamReader
;
}
namespace
kyut
::
watermarker
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
BitStreamReader
&
stream
,
std
::
size_t
divisions
);
...
...
src/snpi.cpp
View file @
df9737a4
...
...
@@ -2,6 +2,7 @@
#include <wasm-io.h>
#include "kyut/BitStreamReader.hpp"
#include "kyut/watermarker/FunctionOrderingWatermarker.hpp"
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
test/CMakeLists.txt
View file @
df9737a4
add_executable
(
test_kyut
test_kyut.cpp
test_BitStreamReader.cpp
kyut/test_BitStreamReader.cpp
kyut/watermarker/test_FunctionOrderingWatermarker.cpp
)
target_link_libraries
(
test_kyut
...
...
test/test_BitStreamReader.cpp
→
test/
kyut/
test_BitStreamReader.cpp
View file @
df9737a4
...
...
@@ -2,15 +2,6 @@
#include <boost/test/unit_test.hpp>
namespace
{
constexpr
std
::
size_t
operator
""
_zu
(
unsigned
long
long
x
)
noexcept
{
return
static_cast
<
std
::
size_t
>
(
x
);
}
constexpr
std
::
uint64_t
operator
""
_u64
(
unsigned
long
long
x
)
noexcept
{
return
static_cast
<
std
::
uint64_t
>
(
x
);
}
}
// namespace
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
bit_stream_reader
)
...
...
@@ -20,53 +11,53 @@ BOOST_AUTO_TEST_CASE(read_bit) {
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
// 0x89 == 0b1000'1001
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
1
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
1
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
2
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
2
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
3
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
3
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
4
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
5
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
5
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
6
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
6
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
7
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
7
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
1
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
1
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
2
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
2
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
3
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
3
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
4
}
);
}
BOOST_AUTO_TEST_CASE
(
read
)
{
constexpr
std
::
uint8_t
data
[
4
]
=
{
0x89
,
0xab
,
0xcd
,
0xef
};
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
0x8
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
0x9
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
std
::
uint64_t
{
0x8
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
4
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
std
::
uint64_t
{
0x9
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
8
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
8
),
0xab
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
8
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
8
),
std
::
uint64_t
{
0xab
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
16
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
16
),
0xcdef
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
16
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
16
),
std
::
uint64_t
{
0xcdef
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
24
),
0x89abcd
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
24
),
std
::
uint64_t
{
0x89abcd
}
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
24
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
24
}
);
}
BOOST_AUTO_TEST_SUITE_END
()
...
...
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
0 → 100644
View file @
df9737a4
#include <kyut/watermarker/FunctionOrderingWatermarker.hpp>
#include <boost/test/unit_test.hpp>
#include <wasm-io.h>
#include <kyut/BitStreamReader.hpp>
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
watermarker
)
BOOST_AUTO_TEST_CASE
(
function_ordering_watermarker
)
{
wasm
::
Module
module
;
wasm
::
ModuleReader
{}.
read
(
"../example/test1.wast"
,
module
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"g1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f3"
);
// Embed 0b00
{
BitStreamReader
s
{{
0
b0000
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"g1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f3"
);
}
// Embed 0b01
{
BitStreamReader
s
{{
0
b0100
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"g1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f3"
);
}
// Embed 0b10
{
BitStreamReader
s
{{
0
b1000
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"g1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f2"
);
}
// Embed 0b11
{
BitStreamReader
s
{{
0
b1100
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"g1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f2"
);
}
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment