Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
ParaEncode
Project
Project
Details
Activity
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
Linshizhi
ParaEncode
Commits
3921fdac
Commit
3921fdac
authored
May 17, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Blk based channel pass unittests
parent
04c6111e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
28 deletions
+149
-28
channel.js
src/channel.js
+21
-19
Channel.spec.js
tests/Channel.spec.js
+128
-9
No files found.
src/channel.js
View file @
3921fdac
...
...
@@ -232,7 +232,6 @@ export class Channel {
}
#
remainBlocks
()
{
console
.
log
(
this
.
#
readPointerCache
,
this
.
#
writePointerCache
);
if
(
this
.
#
readPointerCache
==
this
.
#
writePointerCache
)
{
// Check RBLKS and WBLKS
let
rBlks
=
this
.
#
getRBlks
(),
...
...
@@ -342,6 +341,7 @@ export class Channel {
#
readDataBlks
(
size
)
{
let
buffer
=
undefined
;
let
endPos
=
this
.
#
endPos
-
1
;
let
rEnd
=
this
.
#
readPointerCache
;
this
.
#
writePointerCache
=
this
.
#
getWritePointer
();
...
...
@@ -353,6 +353,7 @@ export class Channel {
return
new
Uint8Array
(
0
);
}
let
rBlks
=
this
.
#
getRBlks
();
buffer
=
new
Uint8Array
(
blksRequired
*
this
.
#
blockSize
);
if
(
this
.
#
readPointerCache
>=
this
.
#
writePointerCache
)
{
...
...
@@ -360,18 +361,26 @@ export class Channel {
let
blks
=
Math
.
floor
(
spaceBetweenEnd
/
this
.
#
blockSize
);
if
(
blks
>=
blksRequired
)
{
buffer
=
new
Uint8Array
(
blksRequired
*
this
.
#
blockSize
);
buffer
.
set
(
this
.
#
buffer
.
subarray
(
this
.
#
readPointerCache
,
this
.
#
readPointerCache
+
(
blksRequired
*
this
.
#
blockSize
)))
return
buffer
;
rEnd
=
this
.
#
readPointerCache
+
(
blksRequired
*
this
.
#
blockSize
);
buffer
.
set
(
this
.
#
buffer
.
subarray
(
this
.
#
readPointerCache
,
rEnd
));
}
else
{
/* Two step to read datas */
// Read two times
rEnd
=
this
.
#
metaSize
+
(
blksRequired
-
blks
)
*
this
.
#
blockSize
;
buffer
.
set
(
this
.
#
buffer
.
subarray
(
this
.
#
readPointerCache
,
blks
*
this
.
#
blockSize
));
buffer
.
set
(
this
.
#
buffer
.
subarray
(
this
.
#
metaSize
,
rEnd
),
blks
*
this
.
#
blockSize
);
}
}
else
if
(
this
.
#
readPointerCache
<
this
.
#
writePointerCache
)
{
rEnd
=
this
.
#
readPointerCache
+
(
blksRequired
*
this
.
#
blockSize
);
buffer
.
set
(
this
.
#
buffer
.
subarray
(
this
.
#
readPointerCache
,
rEnd
));
}
this
.
#
setRBlks
((
rBlks
+
blksRequired
)
%
Math
.
pow
(
2
,
8
));
// Similar to push() must not change readPointer field in SharedMemory
// until all reads done.
this
.
#
readPointerUpdate
(
rEnd
);
return
buffer
;
}
...
...
@@ -405,9 +414,6 @@ export class Channel {
let
plan_1
=
schedule
[
'first'
];
let
plan_2
=
schedule
[
'second'
];
console
.
log
(
plan_1
);
console
.
log
(
plan_2
);
let
endPos
=
undefined
;
let
buffers
=
[];
...
...
@@ -592,16 +598,14 @@ class CopyStrategyInBlock extends CopyStrategy {
retSchedule
.
first
.
pos
=
wPos
;
if
(
blksAbleToWrite
>=
blocksRequired
)
{
retSchedule
.
first
.
size
=
blocksRequired
*
this
.
#
blockSize
;
console
.
log
(
retSchedule
)
return
retSchedule
;
}
else
{
retSchedule
.
first
.
size
=
blksAbleToWrite
*
this
.
#
blockSize
;
blocksRequired
-=
blksAbleToWrite
;
}
/* Second one is required */
retSchedule
.
second
.
pos
=
this
.
#
shift
;
retSchedule
.
second
.
size
=
blocksRequired
*
this
.
#
blockSize
;
}
}
else
if
(
wPos
==
rPos
)
{
// Under the assumption of schedule() 'wPos == rPos' means
// channel is empty
...
...
@@ -613,9 +617,7 @@ class CopyStrategyInBlock extends CopyStrategy {
retSchedule
.
first
.
size
=
blocksRequired
*
this
.
#
blockSize
;
}
args
.
wBlks
+=
blocksRequired
;
console
.
log
(
retSchedule
);
args
.
wBlks
=
(
args
.
wBlks
+
blocksRequired
)
%
Math
.
pow
(
2
,
8
);
return
retSchedule
;
}
}
tests/Channel.spec.js
View file @
3921fdac
import
{
sleep
}
from
'../src/utils.js'
;
import
{
H264EncWWGroup
}
from
'../src/encGroup.js'
;
import
{
Obervable
,
Observable
}
from
'rxjs'
;
import
{
Observable
}
from
'rxjs'
;
import
{
Channel
}
from
'../src/channel.js'
;
const
areEqual
=
(
first
,
second
)
=>
...
...
@@ -314,21 +313,141 @@ describe("Channel Spec", () => {
expect
(
areEqual
(
rBuffer
,
sBuffer
)).
toBe
(
true
);
},
10000
);
});
describe
(
"BLK-BASED Channel Spec"
,
()
=>
{
let
blkSize
=
10
;
let
chn
=
undefined
;
let
blkData
=
new
Uint8Array
([...
Array
(
blkSize
).
keys
()]);
it
(
"BLK-BASED Channel Case 1"
,
async
()
=>
{
const
blkSize
=
10
;
let
chn
=
new
Channel
(
blkSize
*
2
);
beforeEach
(()
=>
{
chn
=
new
Channel
(
blkSize
*
2
);
chn
.
enableBlockMode
(
blkSize
);
});
it
(
"Write Until Full"
,
async
()
=>
{
for
(
let
i
=
0
;
i
<
2
;
++
i
)
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
*
2
);
});
let
blk
=
new
Uint8Array
([...
Array
(
blkSize
).
keys
()]);
it
(
"Write and Read"
,
async
()
=>
{
chn
.
push
(
blkData
);
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
*
2
);
for
(
let
i
=
0
;
i
<
10
;
++
i
)
chn
.
push
(
blk
);
let
data
=
chn
.
readData
(
blkSize
);
expect
(
areEqual
(
blkData
,
data
)).
toBe
(
true
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
*
2
);
data
=
chn
.
readData
(
blkSize
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
});
it
(
"Read Empty"
,
async
()
=>
{
let
data
=
chn
.
readData
(
blkSize
);
expect
(
data
.
byteLength
).
toBe
(
0
);
});
it
(
"Write size smaller than bloksize"
,
()
=>
{
let
wData
=
new
Uint8Array
([
0
,
1
,
2
,
3
,
4
]);
chn
.
push
(
wData
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
});
it
(
"Read size smaller than blocksize"
,
()
=>
{
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
let
data
=
chn
.
readData
(
blkSize
-
1
);
expect
(
data
.
byteLength
).
toBe
(
0
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
});
it
(
"BLK-BASED Channel Case 2"
,
async
()
=>
{
it
(
"Read 0 size"
,
()
=>
{
chn
.
push
(
blkData
);
let
data
=
chn
.
readData
(
0
);
expect
(
data
.
byteLength
).
toBe
(
0
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
});
it
(
"Write 0 size"
,
()
=>
{
let
emptyData
=
new
Uint8Array
(
0
);
chn
.
push
(
emptyData
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
chn
.
push
(
emptyData
);
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
})
it
(
"Two step transfer"
,
async
()
=>
{
let
buffers
=
chn
.
writeStep1
(
blkSize
*
2
);
expect
(
buffers
.
length
).
toBe
(
1
);
expect
(
buffers
[
0
].
byteLength
).
toBe
(
blkSize
*
2
);
buffers
[
0
].
set
(
blkData
,
0
);
buffers
[
0
].
set
(
blkData
,
blkData
.
byteLength
);
chn
.
writeStep2
();
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
*
2
);
for
(
let
i
=
0
;
i
<
2
;
++
i
)
{
let
data
=
chn
.
readData
(
blkSize
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
}
expect
(
chn
.
dataSize
()).
toBe
(
0
);
});
it
(
"Two step write last block"
,
()
=>
{
let
buffers
=
chn
.
writeStep1
(
blkSize
*
1
);
expect
(
buffers
.
length
).
toBe
(
1
);
expect
(
buffers
[
0
].
byteLength
).
toBe
(
blkSize
);
buffers
[
0
].
set
(
blkData
,
0
);
chn
.
writeStep2
();
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
let
data
=
chn
.
readData
(
blkSize
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
// Then write last blocks
for
(
let
i
=
0
;
i
<
2
;
++
i
)
{
buffers
=
chn
.
writeStep1
(
blkSize
*
1
);
expect
(
buffers
.
length
).
toBe
(
1
);
expect
(
buffers
[
0
].
byteLength
).
toBe
(
blkSize
);
buffers
[
0
].
set
(
blkData
,
0
);
chn
.
writeStep2
();
expect
(
chn
.
dataSize
()).
toBe
(
blkSize
);
data
=
chn
.
readData
(
blkSize
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
}
});
it
(
"Data bigger than channle"
,
()
=>
{
let
bigData
=
new
Uint8Array
(
blkSize
*
3
);
chn
.
push
(
bigData
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
// After that chn should work normally
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
10
);
chn
.
push
(
blkData
);
expect
(
chn
.
dataSize
()).
toBe
(
20
);
let
data
=
chn
.
readData
(
blkSize
);
expect
(
chn
.
dataSize
()).
toBe
(
10
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
data
=
chn
.
readData
(
blkSize
);
expect
(
chn
.
dataSize
()).
toBe
(
0
);
expect
(
areEqual
(
data
,
blkData
)).
toBe
(
true
);
});
});
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