aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2020-05-02 18:05:23 +0300
committerlaforge <laforge@osmocom.org>2020-05-16 20:21:48 +0000
commit4752930972ef727b2f1688fb84b158ed24e1ac09 (patch)
tree9aa5970681dbc44cb7a0089d84836bf77b773b81 /tests
parent0a918f028cc9af36dcf997827925355e2b0cad43 (diff)
amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when converted from octet-aligned to bandwidth-efficient mode. It does shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for AMR modes 0, 1, 5, and SID frames because we only remove 6 bits. So old code generated truncated AMR packets for those AMR modes. This patch fixes the length calculation by properly counting bits. Proper bit counting is also bringing us one small step closer to properly handlig multi-frame AMR packets. Change-Id: I0462e054a0adc9080456f3eeea9cab7c229cdb70
Diffstat (limited to 'tests')
-rw-r--r--tests/amr/amr_test.c33
-rw-r--r--tests/amr/amr_test.ok129
2 files changed, 98 insertions, 64 deletions
diff --git a/tests/amr/amr_test.c b/tests/amr/amr_test.c
index fff686c..2f41fe9 100644
--- a/tests/amr/amr_test.c
+++ b/tests/amr/amr_test.c
@@ -44,7 +44,10 @@ char *oa_amr_samples[] = {
"100c4e9ba850e30d5d53d04de41e7c",
"100c6c18e7b7fff53aeb055e7d1c54",
"100c1fb967f7f1fdf547bf2e61c060",
- "a038ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* test pattern */
+ "0004f89d67f1160935bde1996840",
+ "0004633cc7f0630439ffe0000000",
+ "0004eb81fc0758973b9edc782552",
+ "a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* sample with invalid FT */
"END",
};
@@ -56,7 +59,7 @@ char *bwe_amr_samples[] = {
"f3d39a49a09e7a802852e297e8c9246aadf5a45928bfc27177fed8404d97d3b8",
"f3c2155b65131c68682079fab4810911200003b360ae0446000025f11e539dd0",
"f3c381bc7061c9f8507f6029de6115c16e5fa470c243b21b6e35dbb48bd84c00",
- "a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f", /* test pattern */
+ "a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f", /* sample with invalid FT */
"END",
};
@@ -87,7 +90,6 @@ void osmo_amr_oa_to_bwe_test(void)
return;
printf("\n");
printf("Sample No.: %i\n", i);
- len = strlen(oa_amr_samples[i]);
len = osmo_hexparse(oa_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
@@ -102,11 +104,6 @@ void osmo_amr_oa_to_bwe_test(void)
dump_bits(buf, rc);
printf("\n");
printf(" rc: %i\n", rc);
-
- if (rc > 0) {
- OSMO_ASSERT(rc == len - 1);
- OSMO_ASSERT(buf[len - 1] == 0x00);
- }
i++;
}
}
@@ -126,7 +123,6 @@ void osmo_amr_bwe_to_oa_test(void)
return;
printf("\n");
printf("Sample No.: %i\n", i);
- len = strlen(bwe_amr_samples[i]);
len = osmo_hexparse(bwe_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
@@ -142,7 +138,6 @@ void osmo_amr_bwe_to_oa_test(void)
printf("\n");
printf(" rc: %i\n", rc);
- OSMO_ASSERT(rc == len + 1);
i++;
}
}
@@ -151,6 +146,8 @@ void osmo_amr_oa_to_bwe_and_inverse_test(void)
{
uint8_t buf[256];
uint8_t buf_chk[256];
+ struct amr_hdr *oa_hd = (struct amr_hdr *)buf;
+ unsigned int ft;
unsigned int i = 0;
int len;
@@ -163,18 +160,28 @@ void osmo_amr_oa_to_bwe_and_inverse_test(void)
while (1) {
if (strcmp(oa_amr_samples[i], "END") == 0)
return;
- printf("Sample No.: %i...\n", i);
- len = strlen(oa_amr_samples[i]);
+ printf("Sample No.: %i...", i);
len = osmo_hexparse(oa_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
+ i++;
+
+ ft = oa_hd->ft;
+ if (!osmo_amr_ft_valid(ft)) {
+ printf(" skipping a sample with a wrong FT\n");
+ continue;
+ }
+ OSMO_ASSERT(osmo_amr_bytes(ft) + 2 == len);
+ printf(" AMR mode: %d, OA: %d bytes,", ft, len);
memcpy(buf_chk, buf, sizeof(buf));
rc = osmo_amr_oa_to_bwe(buf, len);
OSMO_ASSERT(rc > 0);
+ printf(" BE: %d bytes,", rc);
rc = osmo_amr_bwe_to_oa(buf, rc, sizeof(buf));
+ printf(" OA: %d bytes\n", rc);
+ OSMO_ASSERT(len == rc);
OSMO_ASSERT(memcmp(buf, buf_chk, len) == 0);
- i++;
}
}
diff --git a/tests/amr/amr_test.ok b/tests/amr/amr_test.ok
index ea34fea..af1be82 100644
--- a/tests/amr/amr_test.ok
+++ b/tests/amr/amr_test.ok
@@ -47,23 +47,23 @@ Sample No.: 5
Sample No.: 6
octet aligned: 502c98ab841e491ff7a1a555016a32a3c7f913210630
01010000001011001001100010101011100001000001111001001001000111111111011110100001101001010101010100000001011010100011001010100011110001111111100100010011001000010000011000110000
- bw-efficient: 52e62ae1079247fde86955405a8ca8f1fe44c8418c
- 010100101110011000101010111000010000011110010010010001111111110111101000011010010101010101000000010110101000110010101000111100011111111001000100110010000100000110001100
- rc: 21
+ bw-efficient: 52e62ae1079247fde86955405a8ca8f1fe44c8418c00
+ 01010010111001100010101011100001000001111001001001000111111111011110100001101001010101010100000001011010100011001010100011110001111111100100010011001000010000011000110000000000
+ rc: 22
Sample No.: 7
octet aligned: 502cc5459a0d200e7097c4dfe86ec8d27f1756d776f0
01010000001011001100010101000101100110100000110100100000000011100111000010010111110001001101111111101000011011101100100011010010011111110001011101010110110101110111011011110000
- bw-efficient: 52f151668348039c25f137fa1bb2349fc5d5b5ddbc
- 010100101111000101010001011001101000001101001000000000111001110000100101111100010011011111111010000110111011001000110100100111111100010111010101101101011101110110111100
- rc: 21
+ bw-efficient: 52f151668348039c25f137fa1bb2349fc5d5b5ddbc00
+ 01010010111100010101000101100110100000110100100000000011100111000010010111110001001101111111101000011011101100100011010010011111110001011101010110110101110111011011110000000000
+ rc: 22
Sample No.: 8
octet aligned: 502c42b332081813d7e916e7aa5e80d7fde812b8c080
01010000001011000100001010110011001100100000100000011000000100111101011111101001000101101110011110101010010111101000000011010111111111011110100000010010101110001100000010000000
- bw-efficient: 52d0accc820604f5fa45b9ea97a035ff7a04ae3020
- 010100101101000010101100110011001000001000000110000001001111010111111010010001011011100111101010100101111010000000110101111111110111101000000100101011100011000000100000
- rc: 21
+ bw-efficient: 52d0accc820604f5fa45b9ea97a035ff7a04ae302000
+ 01010010110100001010110011001100100000100000011000000100111101011111101001000101101110011110101010010111101000000011010111111111011110100000010010101110001100000010000000000000
+ rc: 22
Sample No.: 9
octet aligned: 40240343e959c79bacd20c77501054880a718db200
@@ -110,30 +110,51 @@ Sample No.: 14
Sample No.: 15
octet aligned: 100c4e9ba850e30d5d53d04de41e7c
000100000000110001001110100110111010100001010000111000110000110101011101010100111101000001001101111001000001111001111100
- bw-efficient: 10d3a6ea1438c35754f41379079f
- 0001000011010011101001101110101000010100001110001100001101010111010101001111010000010011011110010000011110011111
- rc: 14
+ bw-efficient: 10d3a6ea1438c35754f41379079f00
+ 000100001101001110100110111010100001010000111000110000110101011101010100111101000001001101111001000001111001111100000000
+ rc: 15
Sample No.: 16
octet aligned: 100c6c18e7b7fff53aeb055e7d1c54
000100000000110001101100000110001110011110110111111111111111010100111010111010110000010101011110011111010001110001010100
- bw-efficient: 10db0639edfffd4ebac1579f4715
- 0001000011011011000001100011100111101101111111111111110101001110101110101100000101010111100111110100011100010101
- rc: 14
+ bw-efficient: 10db0639edfffd4ebac1579f471500
+ 000100001101101100000110001110011110110111111111111111010100111010111010110000010101011110011111010001110001010100000000
+ rc: 15
Sample No.: 17
octet aligned: 100c1fb967f7f1fdf547bf2e61c060
000100000000110000011111101110010110011111110111111100011111110111110101010001111011111100101110011000011100000001100000
- bw-efficient: 10c7ee59fdfc7f7d51efcb987018
- 0001000011000111111011100101100111111101111111000111111101111101010100011110111111001011100110000111000000011000
- rc: 14
+ bw-efficient: 10c7ee59fdfc7f7d51efcb98701800
+ 000100001100011111101110010110011111110111111100011111110111110101010001111011111100101110011000011100000001100000000000
+ rc: 15
Sample No.: 18
- octet aligned: a038ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc
- 101000000011100011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111100
- bw-efficient: a3bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f
- 1010001110111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111
- rc: 32
+ octet aligned: 0004f89d67f1160935bde1996840
+ 0000000000000100111110001001110101100111111100010001011000001001001101011011110111100001100110010110100001000000
+ bw-efficient: 007e2759fc45824d6f78665a1000
+ 0000000001111110001001110101100111111100010001011000001001001101011011110111100001100110010110100001000000000000
+ rc: 14
+
+Sample No.: 19
+ octet aligned: 0004633cc7f0630439ffe0000000
+ 0000000000000100011000110011110011000111111100000110001100000100001110011111111111100000000000000000000000000000
+ bw-efficient: 0058cf31fc18c10e7ff800000000
+ 0000000001011000110011110011000111111100000110001100000100001110011111111111100000000000000000000000000000000000
+ rc: 14
+
+Sample No.: 20
+ octet aligned: 0004eb81fc0758973b9edc782552
+ 0000000000000100111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010010
+ bw-efficient: 007ae07f01d625cee7b71e095480
+ 0000000001111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010010000000
+ rc: 14
+
+Sample No.: 21
+ octet aligned: a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc
+ 101000000111100011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111100
+ bw-efficient:
+ (no data)
+ rc: -1
Testing conversion from bw-efficient to octet-aligned:
@@ -141,16 +162,16 @@ Testing conversion from bw-efficient to octet-aligned:
Sample No.: 0
bw-efficient: f4495c7cda8f80
11110100010010010101110001111100110110101000111110000000
- octet aligned: f0442571f36a3e00
- 1111000001000100001001010111000111110011011010100011111000000000
- rc: 8
+ octet aligned: f0442571f36a3e
+ 11110000010001000010010101110001111100110110101000111110
+ rc: 7
Sample No.: 1
bw-efficient: f44aaa6c969780
11110100010010101010101001101100100101101001011110000000
- octet aligned: f0442aa9b25a5e00
- 1111000001000100001010101010100110110010010110100101111000000000
- rc: 8
+ octet aligned: f0442aa9b25a5e
+ 11110000010001000010101010101001101100100101101001011110
+ rc: 7
Sample No.: 2
bw-efficient: f3d09c20e32da600c025a72e0a9b360386e40f87e19282094adc1a11e397d1d4
@@ -183,31 +204,34 @@ Sample No.: 5
Sample No.: 6
bw-efficient: a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f
1010011110111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111
- octet aligned: a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc
- 101000000111100011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111100
- rc: 33
+ octet aligned:
+ (no data)
+ rc: -1
Testing conversion from octet-aligned to bw-efficient and inverse:
-Sample No.: 0...
-Sample No.: 1...
-Sample No.: 2...
-Sample No.: 3...
-Sample No.: 4...
-Sample No.: 5...
-Sample No.: 6...
-Sample No.: 7...
-Sample No.: 8...
-Sample No.: 9...
-Sample No.: 10...
-Sample No.: 11...
-Sample No.: 12...
-Sample No.: 13...
-Sample No.: 14...
-Sample No.: 15...
-Sample No.: 16...
-Sample No.: 17...
-Sample No.: 18...
+Sample No.: 0... AMR mode: 7, OA: 33 bytes, BE: 32 bytes, OA: 33 bytes
+Sample No.: 1... AMR mode: 7, OA: 33 bytes, BE: 32 bytes, OA: 33 bytes
+Sample No.: 2... AMR mode: 7, OA: 33 bytes, BE: 32 bytes, OA: 33 bytes
+Sample No.: 3... AMR mode: 6, OA: 28 bytes, BE: 27 bytes, OA: 28 bytes
+Sample No.: 4... AMR mode: 6, OA: 28 bytes, BE: 27 bytes, OA: 28 bytes
+Sample No.: 5... AMR mode: 6, OA: 28 bytes, BE: 27 bytes, OA: 28 bytes
+Sample No.: 6... AMR mode: 5, OA: 22 bytes, BE: 22 bytes, OA: 22 bytes
+Sample No.: 7... AMR mode: 5, OA: 22 bytes, BE: 22 bytes, OA: 22 bytes
+Sample No.: 8... AMR mode: 5, OA: 22 bytes, BE: 22 bytes, OA: 22 bytes
+Sample No.: 9... AMR mode: 4, OA: 21 bytes, BE: 20 bytes, OA: 21 bytes
+Sample No.: 10... AMR mode: 4, OA: 21 bytes, BE: 20 bytes, OA: 21 bytes
+Sample No.: 11... AMR mode: 4, OA: 21 bytes, BE: 20 bytes, OA: 21 bytes
+Sample No.: 12... AMR mode: 2, OA: 17 bytes, BE: 16 bytes, OA: 17 bytes
+Sample No.: 13... AMR mode: 2, OA: 17 bytes, BE: 16 bytes, OA: 17 bytes
+Sample No.: 14... AMR mode: 2, OA: 17 bytes, BE: 16 bytes, OA: 17 bytes
+Sample No.: 15... AMR mode: 1, OA: 15 bytes, BE: 15 bytes, OA: 15 bytes
+Sample No.: 16... AMR mode: 1, OA: 15 bytes, BE: 15 bytes, OA: 15 bytes
+Sample No.: 17... AMR mode: 1, OA: 15 bytes, BE: 15 bytes, OA: 15 bytes
+Sample No.: 18... AMR mode: 0, OA: 14 bytes, BE: 14 bytes, OA: 14 bytes
+Sample No.: 19... AMR mode: 0, OA: 14 bytes, BE: 14 bytes, OA: 14 bytes
+Sample No.: 20... AMR mode: 0, OA: 14 bytes, BE: 14 bytes, OA: 14 bytes
+Sample No.: 21... skipping a sample with a wrong FT
Testing detection of octet-aligned mode payloads:
@@ -230,6 +254,9 @@ Sample No.: 15 ==>octet aligned
Sample No.: 16 ==>octet aligned
Sample No.: 17 ==>octet aligned
Sample No.: 18 ==>octet aligned
+Sample No.: 19 ==>octet aligned
+Sample No.: 20 ==>octet aligned
+Sample No.: 21 ==>bandwith efficient
Sample No.: 0 ==>bandwith efficient
Sample No.: 1 ==>bandwith efficient
Sample No.: 2 ==>bandwith efficient