Skip to content

Commit 2065edc

Browse files
committed
tests: nrf_cloud: codec/cbor: Fix build after REST removal
The CBOR codec unit-test PR (nrfconnect#27892) and the REST removal PR (nrfconnect#28522) were merged independently and produced a semantic conflict that left net.lib.nrf_cloud.codec.cbor failing to build on main: * The test referenced REST types (nrf_cloud_rest_agnss_request, nrf_cloud_rest_pgps_request, nrf_cloud_rest_agnss_result, NRF_CLOUD_REST_AGNSS_REQ_*, nrf_cloud_rest_fota_execution_decode) that were renamed to their nrf_cloud_coap_* counterparts by the REST removal. * The REST removal made coap_codec.h transitively pull in net/nrf_cloud_coap.h. Its CoAP-disabled fallback redefined enum coap_content_format, conflicting with zephyr/net/coap.h that the test (and the codec source) include directly. * struct nrf_cloud_coap_pgps_request was gated on CONFIG_NRF_CLOUD_COAP in net/nrf_cloud_pgps.h, so building any codec consumer with PGPS but without COAP left the struct undeclared. Fixes applied: * Rename REST types in the test sources to their nrf_cloud_coap_* equivalents. * In nrf_cloud_coap.h, include zephyr/net/coap.h unconditionally so enum coap_content_format always comes from the canonical Zephyr header. Only zephyr/net/coap_client.h stays gated on CONFIG_NRF_CLOUD_COAP since it requires CONFIG_COAP_CLIENT_*. * In nrf_cloud_pgps.h, define struct nrf_cloud_coap_pgps_request unconditionally - it is a pure data carrier and does not require any CoAP machinery. Verified: net.lib.nrf_cloud.codec.cbor and net.lib.nrf_cloud.codec.json both pass on native_sim and qemu_cortex_m3 (266/266 test cases). Signed-off-by: Pascal Hernandez <pascal.hernandez@nordicsemi.no>
1 parent d2fd397 commit 2065edc

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

include/net/nrf_cloud_coap.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ struct nrf_cloud_coap_pgps_request;
2727
struct nrf_cloud_pgps_result;
2828
#endif
2929
#include <net/nrf_cloud_codec.h>
30-
#if defined(CONFIG_NRF_CLOUD_COAP)
30+
/* <zephyr/net/coap.h> is always available and provides
31+
* enum coap_content_format. <zephyr/net/coap_client.h> requires
32+
* CONFIG_COAP_CLIENT_* symbols that only exist when CoAP client is
33+
* enabled, so it is only pulled in when this library is built with
34+
* CoAP support.
35+
*/
3136
#include <zephyr/net/coap.h>
37+
#if defined(CONFIG_NRF_CLOUD_COAP)
3238
#include <zephyr/net/coap_client.h>
3339
#else
3440
/* Work around missing Kconfigs upstream in coap_client.h */
3541
#define coap_client_response_cb_t void *
36-
enum coap_content_format {
37-
dummy
38-
};
3942
struct coap_client {};
4043
struct coap_client_option {};
4144
#endif

include/net/nrf_cloud_pgps.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,18 @@ struct nrf_cloud_pgps_result {
113113
size_t path_sz;
114114
};
115115

116-
#if defined(CONFIG_NRF_CLOUD_COAP)
117-
/** @brief Data required for nRF Cloud Predicted GPS (P-GPS) request */
116+
/** @brief Data required for nRF Cloud Predicted GPS (P-GPS) request.
117+
*
118+
* Defined here unconditionally so callers can construct a P-GPS request
119+
* via @ref nrf_cloud_coap_pgps_url_get without depending on the full
120+
* CoAP transport machinery being enabled.
121+
*/
118122
struct nrf_cloud_coap_pgps_request {
119123
/** Data to be included in the P-GPS request. To omit an item
120124
* use the appropriate `NRF_CLOUD_PGPS_REQ_NO_` define.
121125
*/
122126
const struct gps_pgps_request *pgps_req;
123127
};
124-
#endif /* CONFIG_NRF_CLOUD_COAP */
125128

126129
/** @brief P-GPS error code: current time unknown. */
127130
#define ETIMEUNKNOWN 8000

tests/subsys/net/lib/nrf_cloud/codec/cbor/src/fakes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* - nrf_cloud_calloc / nrf_cloud_free / nrf_cloud_malloc (link-time deps)
2020
*
2121
* The remaining symbols (nrf_cloud_encode_message, nrf_cloud_error_msg_decode,
22-
* nrf_cloud_rest_fota_execution_decode) are only reachable via JSON paths that
22+
* nrf_cloud_coap_fota_execution_decode) are only reachable via JSON paths that
2323
* the CBOR tests do not exercise; they are stubbed out with safe no-op or
2424
* error-returning implementations so that the linker is satisfied.
2525
*
@@ -89,7 +89,7 @@ int nrf_cloud_error_msg_decode(const char *const buf, const char *const app_id,
8989
return -ENOENT;
9090
}
9191

92-
int nrf_cloud_rest_fota_execution_decode(const char *const response,
92+
int nrf_cloud_coap_fota_execution_decode(const char *const response,
9393
struct nrf_cloud_fota_job_info *const job)
9494
{
9595
ARG_UNUSED(response);
@@ -99,7 +99,7 @@ int nrf_cloud_rest_fota_execution_decode(const char *const response,
9999

100100
/* -------------------------------------------------------------------------
101101
* nrf_cloud_agnss_type_array_get — called in the CBOR path of
102-
* coap_codec_agnss_encode when type == NRF_CLOUD_REST_AGNSS_REQ_CUSTOM.
102+
* coap_codec_agnss_encode when type == NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM.
103103
*
104104
* The real implementation parses an nrf_modem_gnss_agnss_data_frame bitmask
105105
* and fills in an array of nrf_cloud_agnss_type values. For unit testing

tests/subsys/net/lib/nrf_cloud/codec/cbor/src/main.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
*/
4242
#include <net/nrf_cloud_codec.h>
4343
#include <net/nrf_cloud_location.h> /* lte_lc.h, wifi_location_common.h, nrf_cloud.h */
44-
#include <net/nrf_cloud_rest.h> /* nrf_cloud_rest_agnss_request/result */
4544
#include <net/nrf_cloud_pgps.h> /* nrf_cloud_pgps_result, gps_pgps_request */
45+
/* nrf_cloud_coap_agnss_request/result, nrf_cloud_coap_pgps_request */
46+
#include <net/nrf_cloud_coap.h>
4647
#include <nrf_modem_gnss.h> /* struct nrf_modem_gnss_agnss_data_frame */
4748
#include <zephyr/net/coap.h> /* COAP_CONTENT_FORMAT_* */
4849
#include "coap_codec.h"
@@ -486,8 +487,8 @@ ZTEST(coap_cbor_agnss, test_encode_custom_type)
486487
* because our stub ignores the content and returns fixed types.
487488
*/
488489
struct nrf_modem_gnss_agnss_data_frame agnss_data = {0};
489-
struct nrf_cloud_rest_agnss_request request = {
490-
.type = NRF_CLOUD_REST_AGNSS_REQ_CUSTOM,
490+
struct nrf_cloud_coap_agnss_request request = {
491+
.type = NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM,
491492
.agnss_req = &agnss_data,
492493
.net_info = NULL,
493494
.filtered = false,
@@ -514,8 +515,8 @@ ZTEST(coap_cbor_agnss, test_encode_with_net_info_and_filter)
514515
.rsrp = 50, /* != LTE_LC_CELL_RSRP_INVALID */
515516
},
516517
};
517-
struct nrf_cloud_rest_agnss_request request = {
518-
.type = NRF_CLOUD_REST_AGNSS_REQ_CUSTOM,
518+
struct nrf_cloud_coap_agnss_request request = {
519+
.type = NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM,
519520
.agnss_req = &agnss_data,
520521
.net_info = &net_info,
521522
.filtered = true,
@@ -533,8 +534,8 @@ ZTEST(coap_cbor_agnss, test_encode_non_custom_type_returns_enotsup)
533534
uint8_t buf[AGNSS_GET_CBOR_MAX_SIZE];
534535
size_t len = sizeof(buf);
535536
struct nrf_modem_gnss_agnss_data_frame agnss_data = {0};
536-
struct nrf_cloud_rest_agnss_request request = {
537-
.type = NRF_CLOUD_REST_AGNSS_REQ_ASSISTANCE, /* not CUSTOM */
537+
struct nrf_cloud_coap_agnss_request request = {
538+
.type = NRF_CLOUD_COAP_AGNSS_REQ_ASSISTANCE, /* not CUSTOM */
538539
.agnss_req = &agnss_data,
539540
};
540541

@@ -548,8 +549,8 @@ ZTEST(coap_cbor_agnss, test_encode_invalid_fmt_returns_enotsup)
548549
uint8_t buf[AGNSS_GET_CBOR_MAX_SIZE];
549550
size_t len = sizeof(buf);
550551
struct nrf_modem_gnss_agnss_data_frame agnss_data = {0};
551-
struct nrf_cloud_rest_agnss_request request = {
552-
.type = NRF_CLOUD_REST_AGNSS_REQ_CUSTOM,
552+
struct nrf_cloud_coap_agnss_request request = {
553+
.type = NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM,
553554
.agnss_req = &agnss_data,
554555
};
555556

@@ -562,7 +563,7 @@ ZTEST(coap_cbor_agnss, test_decode_cbor_fmt_returns_enotsup)
562563
/* A-GNSS responses are binary octet-stream, not CBOR.
563564
* Passing CBOR format must return -ENOTSUP.
564565
*/
565-
struct nrf_cloud_rest_agnss_result result = {0};
566+
struct nrf_cloud_coap_agnss_result result = {0};
566567
const uint8_t dummy[] = {0x01, 0x02};
567568

568569
zassert_equal(coap_codec_agnss_resp_decode(&result, dummy, sizeof(dummy),
@@ -576,7 +577,7 @@ ZTEST(coap_cbor_agnss, test_decode_octet_stream)
576577
*/
577578
static const uint8_t payload[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x02, 0x03, 0x04};
578579
uint8_t out[sizeof(payload)];
579-
struct nrf_cloud_rest_agnss_result result = {
580+
struct nrf_cloud_coap_agnss_result result = {
580581
.buf = out,
581582
.buf_sz = sizeof(out),
582583
};
@@ -592,7 +593,7 @@ ZTEST(coap_cbor_agnss, test_decode_octet_stream_truncated)
592593
/* When result->buf_sz < response length the data is truncated to buf_sz. */
593594
static const uint8_t payload[] = {0x01, 0x02, 0x03, 0x04, 0x05};
594595
uint8_t out[3];
595-
struct nrf_cloud_rest_agnss_result result = {
596+
struct nrf_cloud_coap_agnss_result result = {
596597
.buf = out,
597598
.buf_sz = sizeof(out),
598599
};
@@ -621,7 +622,7 @@ ZTEST(coap_cbor_pgps, test_encode_valid)
621622
.gps_day = 3000,
622623
.gps_time_of_day = 43200,
623624
};
624-
struct nrf_cloud_rest_pgps_request request = {
625+
struct nrf_cloud_coap_pgps_request request = {
625626
.pgps_req = &pgps_req,
626627
};
627628

@@ -642,7 +643,7 @@ ZTEST(coap_cbor_pgps, test_encode_invalid_fmt_returns_enotsup)
642643
.gps_day = 1,
643644
.gps_time_of_day = 0,
644645
};
645-
struct nrf_cloud_rest_pgps_request request = {.pgps_req = &pgps_req};
646+
struct nrf_cloud_coap_pgps_request request = {.pgps_req = &pgps_req};
646647

647648
zassert_equal(coap_codec_pgps_encode(&request, buf, &len,
648649
COAP_CONTENT_FORMAT_APP_JSON), -ENOTSUP);
@@ -658,7 +659,7 @@ ZTEST(coap_cbor_pgps, test_encode_buf_too_small)
658659
.gps_day = 3000,
659660
.gps_time_of_day = 43200,
660661
};
661-
struct nrf_cloud_rest_pgps_request request = {.pgps_req = &pgps_req};
662+
struct nrf_cloud_coap_pgps_request request = {.pgps_req = &pgps_req};
662663

663664
zassert_equal(coap_codec_pgps_encode(&request, buf, &len,
664665
COAP_CONTENT_FORMAT_APP_CBOR), -EINVAL);

0 commit comments

Comments
 (0)