2011-03-20 19:18:19 +01:00
|
|
|
/****************************************************************************
|
2021-06-16 09:22:16 +02:00
|
|
|
* apps/examples/nettest/nettest_target1.c
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02: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
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02: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.
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-21 01:12:27 +01:00
|
|
|
#include "config.h"
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2015-08-27 19:46:42 +02:00
|
|
|
#include <sys/wait.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <stdint.h>
|
2015-08-26 18:35:40 +02:00
|
|
|
#include <stdlib.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <stdio.h>
|
2015-08-26 18:35:40 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "nettest.h"
|
|
|
|
|
2017-06-24 03:14:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
|
|
|
static int server_child(int argc, char *argv[])
|
|
|
|
{
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_server();
|
2017-06-24 03:14:39 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-26 17:06:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* nettest_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
2015-08-27 19:46:42 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
2015-08-26 18:35:40 +02:00
|
|
|
pid_t child;
|
2015-08-27 19:46:42 +02:00
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
int statloc;
|
|
|
|
#endif
|
2015-08-26 18:35:40 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-23 20:21:13 +02:00
|
|
|
/* Parse any command line options */
|
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_cmdline(argc, argv);
|
2017-06-23 20:21:13 +02:00
|
|
|
|
2015-08-26 17:06:41 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
|
|
|
/* Initialize the network */
|
|
|
|
|
2017-06-23 19:40:02 +02:00
|
|
|
nettest_initialize();
|
2015-08-26 17:06:41 +02:00
|
|
|
#endif
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2015-08-26 18:35:40 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
|
|
/* Then perform the server side of the test on a child task */
|
|
|
|
|
2020-05-21 22:17:48 +02:00
|
|
|
child = task_create("Nettest Child",
|
|
|
|
CONFIG_EXAMPLES_NETTEST_DAEMON_PRIORITY,
|
|
|
|
CONFIG_EXAMPLES_NETTEST_DAEMON_STACKSIZE,
|
|
|
|
server_child, NULL);
|
2015-08-26 18:35:40 +02:00
|
|
|
if (child < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to server daemon\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:48 +02:00
|
|
|
usleep(500 * 1000);
|
2015-08-26 18:35:40 +02:00
|
|
|
|
|
|
|
#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER)
|
|
|
|
/* Then perform the server side of the test on this thread */
|
2015-08-26 17:06:41 +02:00
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_server();
|
2015-08-26 18:35:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \
|
|
|
|
defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
|
|
/* Then perform the client side of the test on this thread */
|
2015-08-26 17:06:41 +02:00
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_client();
|
2011-03-20 19:18:19 +01:00
|
|
|
#endif
|
|
|
|
|
2015-08-27 19:46:42 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(CONFIG_SCHED_WAITPID)
|
|
|
|
printf("main: Waiting for the server to exit\n");
|
2020-01-02 13:09:50 +01:00
|
|
|
waitpid(child, &statloc, 0);
|
2015-08-27 19:46:42 +02:00
|
|
|
#endif
|
|
|
|
|
2015-08-26 18:35:40 +02:00
|
|
|
return EXIT_SUCCESS;
|
2011-03-20 19:18:19 +01:00
|
|
|
}
|