mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-23 21:43:51 +01:00
tests/unittests: add tests sock_dns_cache
This commit is contained in:
parent
077a41a719
commit
d09d29a581
@ -54,7 +54,7 @@ extern "C" {
|
||||
* @param[in] family Either AF_INET, AF_INET6 or AF_UNSPEC
|
||||
*
|
||||
* @return the size of the resolved address on success
|
||||
* @return < 0 otherwise
|
||||
* @return <= 0 otherwise
|
||||
*/
|
||||
int sock_dns_cache_query(const char *domain_name, void *addr_out, int family);
|
||||
|
||||
@ -62,12 +62,11 @@ int sock_dns_cache_query(const char *domain_name, void *addr_out, int family);
|
||||
* @brief Add an IP address for a DNS name to the DNS cache
|
||||
*
|
||||
* @param[in] domain_name DNS name to resolve into address
|
||||
* @param[in] addr_out buffer to write result into
|
||||
* @param[in] addr buffer containing the address
|
||||
* @param[in] addr_len length of the address in bytes
|
||||
* @param[in] ttl lifetime of the entry in seconds
|
||||
*/
|
||||
void sock_dns_cache_add(const char *domain_name, const void *addr_out,
|
||||
int addr_len, uint32_t ttl);
|
||||
void sock_dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl);
|
||||
#else
|
||||
static inline int sock_dns_cache_query(const char *domain_name,
|
||||
void *addr_out, int family)
|
||||
@ -78,11 +77,11 @@ static inline int sock_dns_cache_query(const char *domain_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void sock_dns_cache_add(const char *domain_name, const void *addr_out,
|
||||
static inline void sock_dns_cache_add(const char *domain_name, const void *addr,
|
||||
int addr_len, uint32_t ttl)
|
||||
{
|
||||
(void)domain_name;
|
||||
(void)addr_out;
|
||||
(void)addr;
|
||||
(void)addr_len;
|
||||
(void)ttl;
|
||||
}
|
||||
|
||||
1
tests/unittests/tests-sock_dns_cache/Makefile
Normal file
1
tests/unittests/tests-sock_dns_cache/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
2
tests/unittests/tests-sock_dns_cache/Makefile.include
Normal file
2
tests/unittests/tests-sock_dns_cache/Makefile.include
Normal file
@ -0,0 +1,2 @@
|
||||
USEMODULE += gnrc_ipv6
|
||||
USEMODULE += sock_dns_cache
|
||||
53
tests/unittests/tests-sock_dns_cache/tests-sock_dns_cache.c
Normal file
53
tests/unittests/tests-sock_dns_cache/tests-sock_dns_cache.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2022 ML!PA Consulting GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "net/af.h"
|
||||
#include "net/ipv6.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "tests-sock_dns_cache.h"
|
||||
#include "../net/application_layer/sock_dns/dns_cache.h"
|
||||
|
||||
static void test_dns_cache_add(void)
|
||||
{
|
||||
ipv6_addr_t addr_in = IPV6_ADDR_ALL_NODES_IF_LOCAL;
|
||||
ipv6_addr_t addr_out;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.com", &addr_out, AF_INET6));
|
||||
|
||||
/* add DNS entry, set it to expire in 1s */
|
||||
sock_dns_cache_add("example.com", &addr_in, sizeof(addr_in), 1);
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(addr_out), sock_dns_cache_query("example.com", &addr_out, AF_INET6));
|
||||
TEST_ASSERT_EQUAL_INT(0, memcmp(&addr_in, &addr_out, sizeof(addr_in)));
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.com", &addr_out, AF_INET));
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("alt.example.com", &addr_out, AF_INET6));
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.comm", &addr_out, AF_INET6));
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.co", &addr_out, AF_INET6));
|
||||
|
||||
ztimer_sleep(ZTIMER_USEC, 2000000);
|
||||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.com", &addr_out, AF_INET6));
|
||||
}
|
||||
|
||||
Test *tests_sock_dns_cache_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_dns_cache_add),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(sock_dns_cache_tests, NULL, NULL, fixtures);
|
||||
|
||||
return (Test *)&sock_dns_cache_tests;
|
||||
}
|
||||
|
||||
void tests_sock_dns_cache(void)
|
||||
{
|
||||
TESTS_RUN(tests_sock_dns_cache_tests());
|
||||
}
|
||||
44
tests/unittests/tests-sock_dns_cache/tests-sock_dns_cache.h
Normal file
44
tests/unittests/tests-sock_dns_cache/tests-sock_dns_cache.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 ML!PA Consulting GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup unittests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Unittests for the ``sock_dns_cache`` module
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#ifndef TESTS_SOCK_DNS_CACHE_H
|
||||
#define TESTS_SOCK_DNS_CACHE_H
|
||||
|
||||
#include "embUnit.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The entry point of this test suite.
|
||||
*/
|
||||
void tests_sock_dns_cache(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests for sock_dns_cache
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_sock_dns_cache_tests(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_SOCK_DNS_CACHE_H */
|
||||
/** @} */
|
||||
Loading…
x
Reference in New Issue
Block a user