2014-06-05 18:43:20 +02:00
|
|
|
/****************************************************************************
|
2017-05-09 15:34:59 +02:00
|
|
|
* mm/iob/iob_test.c
|
2014-06-05 18:43:20 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-06-05 18:43:20 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-06-05 18:43:20 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Unit test driver. This is of historical interest only since it requires
|
|
|
|
* and custom build setup and modifications to the iob source and header
|
|
|
|
* files.
|
2014-06-05 18:43:20 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "iob.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-02-26 14:35:55 +01:00
|
|
|
static uint8_t buffer1[16384];
|
|
|
|
static uint8_t buffer2[16384];
|
2014-06-05 18:43:20 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void dump_chain(struct iob_s *iob)
|
|
|
|
{
|
2014-06-06 02:50:30 +02:00
|
|
|
struct iob_s *head = iob;
|
|
|
|
unsigned int pktlen;
|
2014-06-05 18:43:20 +02:00
|
|
|
int n;
|
2015-10-04 23:28:54 +02:00
|
|
|
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("=========================================================\n");
|
2014-06-09 21:54:47 +02:00
|
|
|
printf("pktlen: %d\n", iob->io_pktlen);
|
2014-06-05 18:43:20 +02:00
|
|
|
|
|
|
|
n = 0;
|
2014-06-06 02:50:30 +02:00
|
|
|
pktlen = 0;
|
|
|
|
|
2014-06-05 18:43:20 +02:00
|
|
|
while (iob)
|
|
|
|
{
|
2014-06-12 16:35:59 +02:00
|
|
|
printf("%d. len=%d, offset=%d\n", n, iob->io_len, iob->io_offset);
|
2014-06-05 18:43:20 +02:00
|
|
|
|
2014-06-06 02:50:30 +02:00
|
|
|
pktlen += iob->io_len;
|
2014-06-06 17:35:31 +02:00
|
|
|
iob = iob->io_flink;
|
2014-06-05 18:43:20 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2014-06-06 02:50:30 +02:00
|
|
|
if (pktlen != head->io_pktlen)
|
|
|
|
{
|
|
|
|
printf("ERROR: Bad packet length=%u, actual=%u\n",
|
|
|
|
head->io_pktlen, pktlen);
|
|
|
|
}
|
|
|
|
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("=========================================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: main
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* A simple unit test for the I/O buffer logic
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct iob_s *iob;
|
|
|
|
int nbytes;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
iob_initialize();
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = iob_alloc(false);
|
2014-06-05 18:43:20 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 4096; i++)
|
|
|
|
{
|
|
|
|
buffer1[i] = (uint8_t)(i & 0xff);
|
|
|
|
}
|
2020-02-13 14:58:07 +01:00
|
|
|
|
2014-06-05 18:43:20 +02:00
|
|
|
memset(buffer2, 0xff, 4096);
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_copyin(iob, buffer2, 47, 0, false);
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("Copy IN: 47, offset 0\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_copyin(iob, buffer1, 4096, 47, false);
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("Copy IN: 4096, offset 47\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
nbytes = iob_copyout(buffer2, iob, 4096, 47);
|
|
|
|
printf("Copy OUT: %d, offset 47\n", nbytes);
|
|
|
|
|
|
|
|
if (memcmp(buffer1, buffer2, nbytes) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Buffer1 does not match buffer2\n");
|
|
|
|
}
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = iob_trimhead(iob, 47);
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("Trim: 47 from the beginning of the list\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = iob_trimtail(iob, 493);
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("Trim: 493 from the end of the list\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
nbytes = iob_copyout(buffer2, iob, 4096, 0);
|
|
|
|
printf("Copy OUT: %d, offset 0\n", nbytes);
|
|
|
|
|
|
|
|
if (memcmp(buffer1, buffer2, nbytes) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Buffer1 does not match buffer2\n");
|
|
|
|
}
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = iob_trimhead(iob, 1362);
|
2014-06-05 18:43:20 +02:00
|
|
|
printf("Trim: 1362 from the beginning of the list\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
nbytes = iob_copyout(buffer2, iob, 4096, 0);
|
|
|
|
printf("Copy OUT: %d, offset 0\n", nbytes);
|
|
|
|
|
|
|
|
if (memcmp(&buffer1[1362], buffer2, nbytes) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Buffer1 does not match buffer2\n");
|
|
|
|
}
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = iob_pack(iob);
|
2014-06-06 02:50:30 +02:00
|
|
|
printf("Packed\n");
|
2014-06-05 18:43:20 +02:00
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
nbytes = iob_copyout(buffer2, iob, 4096, 0);
|
|
|
|
printf("Copy OUT: %d, offset 0\n", nbytes);
|
|
|
|
|
|
|
|
if (memcmp(&buffer1[1362], buffer2, nbytes) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Buffer1 does not match buffer2\n");
|
|
|
|
}
|
|
|
|
|
2023-08-17 09:55:32 +02:00
|
|
|
nbytes = iob->io_pktlen;
|
|
|
|
|
|
|
|
iob_reserve(iob, 55);
|
|
|
|
printf("Reserve: adjust offset to 55\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
if (iob->io_offset != 55 || iob->io_pktlen + 55 != nbytes)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Offset or packet length wrong\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
iob_reserve(iob, 28);
|
|
|
|
printf("Reserve: adjust offset to 28\n");
|
|
|
|
dump_chain(iob);
|
|
|
|
|
|
|
|
if (iob->io_offset != 28 || iob->io_pktlen + 28 != nbytes)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Offset or packet length wrong\n");
|
|
|
|
}
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
while (iob) iob = iob_free(iob);
|
2014-06-05 18:43:20 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: my_assert
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* A stand-in for the NuttX assertion routine.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void my_assert(bool value)
|
|
|
|
{
|
2015-10-04 23:04:00 +02:00
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Assertion failed\n");
|
2014-06-05 18:43:20 +02:00
|
|
|
|
2015-10-04 23:04:00 +02:00
|
|
|
abort();
|
|
|
|
}
|
2014-06-05 18:43:20 +02:00
|
|
|
}
|