Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zlib-wasm
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
zlib-wasm
Commits
38bd57e8
Commit
38bd57e8
authored
Nov 11, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add deflate/inflate tests
parent
400efaf4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
8 deletions
+62
-8
build.js
build.js
+12
-4
import.h
src/import.h
+2
-0
zlib-exports.c
src/zlib-exports.c
+42
-2
test.js
test.js
+6
-2
No files found.
build.js
View file @
38bd57e8
...
...
@@ -66,8 +66,6 @@ async function opt(input, output, optflags, cwd) {
}
const
srcs
=
[
'zlib-exports'
,
'zlib/adler32'
,
'zlib/compress'
,
'zlib/crc32'
,
...
...
@@ -93,9 +91,19 @@ const srcs = [
srcs
.
map
(
src
=>
clang
(
`../src/
${
src
}
.c`
,
`./
${
src
}
.bc`
,
cflags
,
buildDir
)),
);
// *.bc -> zlib.bc
// *.c -> *.bc
await
clang
(
`../src/zlib-exports.c`
,
`./zlib-exports.bc`
,
cflags
,
buildDir
);
// *.bc -> zlib-lib.bc
await
link
([
...
srcs
.
map
(
s
=>
`./
${
s
}
.bc`
),
],
`./zlib-lib.bc`
,
[
],
buildDir
);
// zlib-exports.bc zlib-lib.bc -> zlib.bc
await
link
([
...
srcs
.
map
(
src
=>
`./
${
src
}
.bc`
),
`./zlib-exports.bc`
,
`./zlib-lib.bc`
,
`
${
cli
.
basedir
}
/lib/webassembly.bc`
,
],
'zlib.bc'
,
[
'-only-needed'
,
...
...
src/import.h
View file @
38bd57e8
#pragma once
void
print
(
int
);
src/zlib-exports.c
View file @
38bd57e8
#include <webassembly.h>
#include <stdlib.h>
#include <memory.h>
#include <zlib.h>
#include "import.h"
export
int
add2
(
int
a
,
int
b
)
{
return
a
+
b
;
#define RAW_DATA_SIZE ((uInt)2 * 1024 * 1024)
static
unsigned
char
*
make_random_bytes
(
uInt
size
)
{
unsigned
char
*
buffer
=
malloc
(
size
);
for
(
uInt
i
=
0
;
i
<
size
;
i
++
)
{
buffer
[
i
]
=
rand
()
>>
1
;
}
return
buffer
;
}
export
int
run_test
(
void
)
{
// Make a random byte sequence
srand
(
0
);
unsigned
char
*
raw_bytes
=
make_random_bytes
(
RAW_DATA_SIZE
);
int
level
=
9
;
// Deflate the random sequence
uLongf
deflated_size
=
compressBound
(
RAW_DATA_SIZE
);
unsigned
char
*
deflated_bytes
=
malloc
(
deflated_size
);
compress2
(
deflated_bytes
,
&
deflated_size
,
raw_bytes
,
RAW_DATA_SIZE
,
level
);
// Inflate the random sequence
uLongf
inflated_size
=
RAW_DATA_SIZE
;
unsigned
char
*
inflated_bytes
=
malloc
(
RAW_DATA_SIZE
);
uncompress
(
inflated_bytes
,
&
inflated_size
,
deflated_bytes
,
deflated_size
);
// Validation
if
(
inflated_size
!=
RAW_DATA_SIZE
||
memcmp
(
inflated_bytes
,
raw_bytes
,
RAW_DATA_SIZE
)
!=
0
)
{
return
1
;
}
// Release the buffers
free
(
deflated_bytes
);
free
(
raw_bytes
);
return
0
;
}
test.js
View file @
38bd57e8
...
...
@@ -2,7 +2,11 @@ const assert = require('assert');
const
wasm
=
require
(
'webassembly'
);
(
async
()
=>
{
const
zlib
=
await
wasm
.
load
(
`
${
__dirname
}
/build/zlib.wasm`
);
const
zlib
=
await
wasm
.
load
(
`
${
__dirname
}
/build/zlib.wasm`
,
{
imports
:
{
print
:
console
.
log
,
},
});
assert
.
strictEqual
(
zlib
.
exports
.
add2
(
8
,
5
),
13
);
assert
.
strictEqual
(
zlib
.
exports
.
run_test
(),
0
);
})();
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