exporting_doubles.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "test_exporting_engine.h"
  3. struct engine *__real_read_exporting_config();
  4. struct engine *__wrap_read_exporting_config()
  5. {
  6. function_called();
  7. return mock_ptr_type(struct engine *);
  8. }
  9. struct engine *__mock_read_exporting_config()
  10. {
  11. struct engine *engine = calloc(1, sizeof(struct engine));
  12. engine->config.hostname = strdupz("test_engine_host");
  13. engine->config.update_every = 3;
  14. engine->instance_root = calloc(1, sizeof(struct instance));
  15. struct instance *instance = engine->instance_root;
  16. instance->engine = engine;
  17. instance->config.type = EXPORTING_CONNECTOR_TYPE_GRAPHITE;
  18. instance->config.name = strdupz("instance_name");
  19. instance->config.destination = strdupz("localhost");
  20. instance->config.username = strdupz("");
  21. instance->config.password = strdupz("");
  22. instance->config.prefix = strdupz("netdata");
  23. instance->config.hostname = strdupz("test-host");
  24. instance->config.update_every = 1;
  25. instance->config.buffer_on_failures = 10;
  26. instance->config.timeoutms = 10000;
  27. instance->config.charts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
  28. instance->config.hosts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
  29. instance->config.options = EXPORTING_SOURCE_DATA_AS_COLLECTED | EXPORTING_OPTION_SEND_NAMES;
  30. return engine;
  31. }
  32. int __real_init_connectors(struct engine *engine);
  33. int __wrap_init_connectors(struct engine *engine)
  34. {
  35. function_called();
  36. check_expected_ptr(engine);
  37. return mock_type(int);
  38. }
  39. int __real_mark_scheduled_instances(struct engine *engine);
  40. int __wrap_mark_scheduled_instances(struct engine *engine)
  41. {
  42. function_called();
  43. check_expected_ptr(engine);
  44. return mock_type(int);
  45. }
  46. NETDATA_DOUBLE __real_exporting_calculate_value_from_stored_data(
  47. struct instance *instance,
  48. RRDDIM *rd,
  49. time_t *last_timestamp);
  50. NETDATA_DOUBLE __wrap_exporting_calculate_value_from_stored_data(
  51. struct instance *instance,
  52. RRDDIM *rd,
  53. time_t *last_timestamp)
  54. {
  55. (void)instance;
  56. (void)rd;
  57. *last_timestamp = 15052;
  58. function_called();
  59. return mock_type(NETDATA_DOUBLE);
  60. }
  61. int __real_prepare_buffers(struct engine *engine);
  62. int __wrap_prepare_buffers(struct engine *engine)
  63. {
  64. function_called();
  65. check_expected_ptr(engine);
  66. return mock_type(int);
  67. }
  68. void __wrap_create_main_rusage_chart(RRDSET **st_rusage, RRDDIM **rd_user, RRDDIM **rd_system)
  69. {
  70. function_called();
  71. check_expected_ptr(st_rusage);
  72. check_expected_ptr(rd_user);
  73. check_expected_ptr(rd_system);
  74. }
  75. void __wrap_send_main_rusage(RRDSET *st_rusage, RRDDIM *rd_user, RRDDIM *rd_system)
  76. {
  77. function_called();
  78. check_expected_ptr(st_rusage);
  79. check_expected_ptr(rd_user);
  80. check_expected_ptr(rd_system);
  81. }
  82. int __wrap_send_internal_metrics(struct instance *instance)
  83. {
  84. function_called();
  85. check_expected_ptr(instance);
  86. return mock_type(int);
  87. }
  88. int __wrap_rrdhost_is_exportable(struct instance *instance, RRDHOST *host)
  89. {
  90. function_called();
  91. check_expected_ptr(instance);
  92. check_expected_ptr(host);
  93. return mock_type(int);
  94. }
  95. int __wrap_rrdset_is_exportable(struct instance *instance, RRDSET *st)
  96. {
  97. function_called();
  98. check_expected_ptr(instance);
  99. check_expected_ptr(st);
  100. return mock_type(int);
  101. }
  102. int __mock_start_batch_formatting(struct instance *instance)
  103. {
  104. function_called();
  105. check_expected_ptr(instance);
  106. return mock_type(int);
  107. }
  108. int __mock_start_host_formatting(struct instance *instance, RRDHOST *host)
  109. {
  110. function_called();
  111. check_expected_ptr(instance);
  112. check_expected_ptr(host);
  113. return mock_type(int);
  114. }
  115. int __mock_start_chart_formatting(struct instance *instance, RRDSET *st)
  116. {
  117. function_called();
  118. check_expected_ptr(instance);
  119. check_expected_ptr(st);
  120. return mock_type(int);
  121. }
  122. int __mock_metric_formatting(struct instance *instance, RRDDIM *rd)
  123. {
  124. function_called();
  125. check_expected_ptr(instance);
  126. check_expected_ptr(rd);
  127. return mock_type(int);
  128. }
  129. int __mock_end_chart_formatting(struct instance *instance, RRDSET *st)
  130. {
  131. function_called();
  132. check_expected_ptr(instance);
  133. check_expected_ptr(st);
  134. return mock_type(int);
  135. }
  136. int __mock_variables_formatting(struct instance *instance, RRDHOST *host)
  137. {
  138. function_called();
  139. check_expected_ptr(instance);
  140. check_expected_ptr(host);
  141. return mock_type(int);
  142. }
  143. int __mock_end_host_formatting(struct instance *instance, RRDHOST *host)
  144. {
  145. function_called();
  146. check_expected_ptr(instance);
  147. check_expected_ptr(host);
  148. return mock_type(int);
  149. }
  150. int __mock_end_batch_formatting(struct instance *instance)
  151. {
  152. function_called();
  153. check_expected_ptr(instance);
  154. return mock_type(int);
  155. }
  156. int __wrap_simple_connector_end_batch(struct instance *instance)
  157. {
  158. function_called();
  159. check_expected_ptr(instance);
  160. return mock_type(int);
  161. }
  162. #if ENABLE_PROMETHEUS_REMOTE_WRITE
  163. void *__wrap_init_write_request()
  164. {
  165. function_called();
  166. return mock_ptr_type(void *);
  167. }
  168. void __wrap_add_host_info(
  169. void *write_request_p,
  170. const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp)
  171. {
  172. function_called();
  173. check_expected_ptr(write_request_p);
  174. check_expected_ptr(name);
  175. check_expected_ptr(instance);
  176. check_expected_ptr(application);
  177. check_expected_ptr(version);
  178. check_expected(timestamp);
  179. }
  180. void __wrap_add_label(void *write_request_p, char *key, char *value)
  181. {
  182. function_called();
  183. check_expected_ptr(write_request_p);
  184. check_expected_ptr(key);
  185. check_expected_ptr(value);
  186. }
  187. void __wrap_add_metric(
  188. void *write_request_p,
  189. const char *name, const char *chart, const char *family, const char *dimension,
  190. const char *instance, const double value, const int64_t timestamp)
  191. {
  192. function_called();
  193. check_expected_ptr(write_request_p);
  194. check_expected_ptr(name);
  195. check_expected_ptr(chart);
  196. check_expected_ptr(family);
  197. check_expected_ptr(dimension);
  198. check_expected_ptr(instance);
  199. check_expected(value);
  200. check_expected(timestamp);
  201. }
  202. #endif // ENABLE_PROMETHEUS_REMOTE_WRITE
  203. #if HAVE_KINESIS
  204. void __wrap_aws_sdk_init()
  205. {
  206. function_called();
  207. }
  208. void __wrap_kinesis_init(
  209. void *kinesis_specific_data_p, const char *region, const char *access_key_id, const char *secret_key,
  210. const long timeout)
  211. {
  212. function_called();
  213. check_expected_ptr(kinesis_specific_data_p);
  214. check_expected_ptr(region);
  215. check_expected_ptr(access_key_id);
  216. check_expected_ptr(secret_key);
  217. check_expected(timeout);
  218. }
  219. void __wrap_kinesis_put_record(
  220. void *kinesis_specific_data_p, const char *stream_name, const char *partition_key, const char *data,
  221. size_t data_len)
  222. {
  223. function_called();
  224. check_expected_ptr(kinesis_specific_data_p);
  225. check_expected_ptr(stream_name);
  226. check_expected_ptr(partition_key);
  227. check_expected_ptr(data);
  228. check_expected_ptr(data);
  229. check_expected(data_len);
  230. }
  231. int __wrap_kinesis_get_result(void *request_outcomes_p, char *error_message, size_t *sent_bytes, size_t *lost_bytes)
  232. {
  233. function_called();
  234. check_expected_ptr(request_outcomes_p);
  235. check_expected_ptr(error_message);
  236. check_expected_ptr(sent_bytes);
  237. check_expected_ptr(lost_bytes);
  238. return mock_type(int);
  239. }
  240. #endif // HAVE_KINESIS
  241. #if ENABLE_EXPORTING_PUBSUB
  242. int __wrap_pubsub_init(
  243. void *pubsub_specific_data_p, char *error_message, const char *destination, const char *credentials_file,
  244. const char *project_id, const char *topic_id)
  245. {
  246. function_called();
  247. check_expected_ptr(pubsub_specific_data_p);
  248. check_expected_ptr(error_message);
  249. check_expected_ptr(destination);
  250. check_expected_ptr(credentials_file);
  251. check_expected_ptr(project_id);
  252. check_expected_ptr(topic_id);
  253. return mock_type(int);
  254. }
  255. int __wrap_pubsub_add_message(void *pubsub_specific_data_p, char *data)
  256. {
  257. function_called();
  258. check_expected_ptr(pubsub_specific_data_p);
  259. check_expected_ptr(data);
  260. return mock_type(int);
  261. }
  262. int __wrap_pubsub_publish(
  263. void *pubsub_specific_data_p, char *error_message, size_t buffered_metrics, size_t buffered_bytes)
  264. {
  265. function_called();
  266. check_expected_ptr(pubsub_specific_data_p);
  267. check_expected_ptr(error_message);
  268. check_expected(buffered_metrics);
  269. check_expected(buffered_bytes);
  270. return mock_type(int);
  271. }
  272. int __wrap_pubsub_get_result(
  273. void *pubsub_specific_data_p, char *error_message,
  274. size_t *sent_metrics, size_t *sent_bytes, size_t *lost_metrics, size_t *lost_bytes)
  275. {
  276. function_called();
  277. check_expected_ptr(pubsub_specific_data_p);
  278. check_expected_ptr(error_message);
  279. check_expected_ptr(sent_metrics);
  280. check_expected_ptr(sent_bytes);
  281. check_expected_ptr(lost_metrics);
  282. check_expected_ptr(lost_bytes);
  283. return mock_type(int);
  284. }
  285. #endif // ENABLE_EXPORTING_PUBSUB
  286. #if HAVE_MONGOC
  287. void __wrap_mongoc_init()
  288. {
  289. function_called();
  290. }
  291. mongoc_uri_t * __wrap_mongoc_uri_new_with_error (const char *uri_string, bson_error_t *error)
  292. {
  293. function_called();
  294. check_expected_ptr(uri_string);
  295. check_expected_ptr(error);
  296. return mock_ptr_type(mongoc_uri_t *);
  297. }
  298. int32_t __wrap_mongoc_uri_get_option_as_int32(const mongoc_uri_t *uri, const char *option, int32_t fallback)
  299. {
  300. function_called();
  301. check_expected_ptr(uri);
  302. check_expected_ptr(option);
  303. check_expected(fallback);
  304. return mock_type(int32_t);
  305. }
  306. bool __wrap_mongoc_uri_set_option_as_int32 (const mongoc_uri_t *uri, const char *option, int32_t value)
  307. {
  308. function_called();
  309. check_expected_ptr(uri);
  310. check_expected_ptr(option);
  311. check_expected(value);
  312. return mock_type(bool);
  313. }
  314. mongoc_client_t * __wrap_mongoc_client_new_from_uri (const mongoc_uri_t *uri)
  315. {
  316. function_called();
  317. check_expected_ptr(uri);
  318. return mock_ptr_type(mongoc_client_t *);
  319. }
  320. bool __wrap_mongoc_client_set_appname (mongoc_client_t *client, const char *appname)
  321. {
  322. function_called();
  323. check_expected_ptr(client);
  324. check_expected_ptr(appname);
  325. return mock_type(bool);
  326. }
  327. mongoc_collection_t *
  328. __wrap_mongoc_client_get_collection(mongoc_client_t *client, const char *db, const char *collection)
  329. {
  330. function_called();
  331. check_expected_ptr(client);
  332. check_expected_ptr(db);
  333. check_expected_ptr(collection);
  334. return mock_ptr_type(mongoc_collection_t *);
  335. }
  336. void __wrap_mongoc_uri_destroy (mongoc_uri_t *uri)
  337. {
  338. function_called();
  339. check_expected_ptr(uri);
  340. }
  341. bool __wrap_mongoc_collection_insert_many(
  342. mongoc_collection_t *collection,
  343. const bson_t **documents,
  344. size_t n_documents,
  345. const bson_t *opts,
  346. bson_t *reply,
  347. bson_error_t *error)
  348. {
  349. function_called();
  350. check_expected_ptr(collection);
  351. check_expected_ptr(documents);
  352. check_expected(n_documents);
  353. check_expected_ptr(opts);
  354. check_expected_ptr(reply);
  355. check_expected_ptr(error);
  356. return mock_type(bool);
  357. }
  358. #endif // HAVE_MONGOC