Skip to content

Commit

Permalink
test: fix jbuf tests
Browse files Browse the repository at this point in the history
`jbuf_get()` now holds back packets/frames until a new frame was put into jbuf.
It returns EAGAIN in order to reduce buffered frames only one by one and
slowly.
  • Loading branch information
cspiel1 committed Jul 30, 2024
1 parent 0966e58 commit e56e27f
Showing 1 changed file with 67 additions and 31 deletions.
98 changes: 67 additions & 31 deletions test/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,79 +33,102 @@ int test_jbuf(void)
}

/* Empty list */
ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

/* One frame */
memset(&hdr, 0, sizeof(hdr));
hdr.seq = 160;
hdr.ts = 1;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);
ASSERT_EQ(EALREADY, jbuf_put(jb, &hdr, frv[0]));
err = jbuf_put(jb, &hdr, frv[0]);
ASSERT_EQ(EALREADY, err);

err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
ASSERT_EQ(160, hdr2.seq);
ASSERT_EQ(frv[0], mem);
mem = mem_deref(mem);

if (ENOENT != jbuf_get(jb, &hdr2, &mem)) {err = EINVAL; goto out;}

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

/* Two frames */
hdr.seq = 320;
hdr.seq = 161;
hdr.ts = 1;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

hdr.seq = 480;
hdr.seq = 162;
hdr.ts = 2;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

ASSERT_EQ(EAGAIN, jbuf_get(jb, &hdr2, &mem));
if (320 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[0]) {err = EINVAL; goto out;}
err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
ASSERT_EQ(161, hdr2.seq);
ASSERT_EQ(frv[0], mem);
mem = mem_deref(mem);

hdr.seq = 163;
hdr.ts = 3;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
if (480 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[1]) {err = EINVAL; goto out;}
ASSERT_EQ(162, hdr2.seq);
ASSERT_EQ(frv[1], mem);
mem = mem_deref(mem);

if (ENOENT != jbuf_get(jb, &hdr2, &mem)) {err = EINVAL; goto out;}

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

/* Three frames */
hdr.seq = 800;
hdr.seq = 165;
hdr.ts = 5;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

hdr.seq = 640;
hdr.seq = 164;
hdr.ts = 4;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

hdr.seq = 960;
hdr.seq = 166;
hdr.ts = 6;
err = jbuf_put(jb, &hdr, frv[2]);
TEST_ERR(err);

/* nfa <= jb->nf*JBUF_EMA_FAC */
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(EAGAIN, err);
if (640 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[0]) {err = EINVAL; goto out;}
ASSERT_EQ(163, hdr2.seq);
ASSERT_EQ(frv[0], mem);
mem = mem_deref(mem);

ASSERT_EQ(EAGAIN, jbuf_get(jb, &hdr2, &mem));
if (800 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[1]) {err = EINVAL; goto out;}
err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
ASSERT_EQ(164, hdr2.seq);
ASSERT_EQ(frv[0], mem);
mem = mem_deref(mem);

hdr.seq = 167;
hdr.ts = 7;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
if (960 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[2]) {err = EINVAL; goto out;}
ASSERT_EQ(165, hdr2.seq);
ASSERT_EQ(frv[1], mem);
mem = mem_deref(mem);

if (ENOENT != jbuf_get(jb, &hdr2, &mem)) {err = EINVAL; goto out;}
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

err = 0;


out:
Expand Down Expand Up @@ -144,31 +167,40 @@ int test_jbuf_frames(void)
}

/* Empty list */
ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

/* Two frames */
hdr.seq = 160;
hdr.ts = 160;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);
ASSERT_EQ(EALREADY, jbuf_put(jb, &hdr, frv[0]));
err = jbuf_put(jb, &hdr, frv[0]);
ASSERT_EQ(EALREADY, err);

/* not able to decide that frame is complete */
ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

hdr.seq = 161;
hdr.ts = 161;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

hdr.seq = 162;
hdr.ts = 162;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

/* detected complete frame */
err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
ASSERT_EQ(160, hdr2.seq);
ASSERT_EQ(mem, frv[0]);
mem = mem_deref(mem);

ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));
err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(ENOENT, err);

/* Four frames */
jbuf_flush(jb);
Expand All @@ -195,11 +227,15 @@ int test_jbuf_frames(void)
mem = mem_deref(mem);

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(EAGAIN, err);
TEST_ERR(err)
ASSERT_EQ(2, hdr2.seq);
ASSERT_EQ(mem, frv[1]);
mem = mem_deref(mem);

hdr.seq = hdr.ts = 5;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(0, err);
ASSERT_EQ(3, hdr2.seq);
Expand Down Expand Up @@ -235,7 +271,7 @@ int test_jbuf_video_frames(void)
memset(&hdr2, 0, sizeof(hdr2));
hdr.ssrc = 1;

err = jbuf_alloc(&jb, 1, 3);
err = jbuf_alloc(&jb, 1, 2);
TEST_ERR(err);

err = jbuf_resize(jb, 10);
Expand Down Expand Up @@ -358,7 +394,7 @@ int test_jbuf_video_frames(void)
ASSERT_EQ(3, jbuf_packets(jb));

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(EAGAIN, err);
TEST_ERR(err);
mem = mem_deref(mem);
ASSERT_EQ(2, jbuf_frames(jb));
ASSERT_EQ(2, jbuf_packets(jb));
Expand Down

0 comments on commit e56e27f

Please sign in to comment.