aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_vpe_api.py
AgeCommit message (Collapse)AuthorFilesLines
2019-07-31api papi: add alias for timestamp(datetime)/timedeltaPaul Vinciguerra1-10/+19
Now that we have support for f64: - create explicit types for timestamp(datetime)/timedelta - update log_details to use timestamp and remove redundant string representation. If you need the string representation, in python do str(timestamp). If you prefer the raw f64 value, the client can pass in the _no_type_conversion option. Type: feature Change-Id: I547b5fa7122d2afa12628b7db0192c23babbbae8 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-07-08api: Implement log_dump/log_detailsPaul Vinciguerra1-0/+46
- Replaces the need to screen scrape "show log". - Adds an api to return the system time. When running over a socket, the api client may have different time than the vpp host. expected use: vpp_time_before_command = self.vapi.show_vpe_system_time_ticks().vpe_system_time_ticks <run some commands> log_output = self.vapi.log_dump(start_timestamp=vpp_time_before_command) Depends-on: https://gerrit.fd.io/r/20484 Depends-on: https://gerrit.fd.io/r/#/c/19581/ ============================================================================== TestVpeApi ============================================================================== log_details(_0=838, context=3, timestamp_ticks=2.4954863503546518e+48, level=<vl_api_log_level_t.VPE_API_LOG_LEVEL_WARNING: 4>, timestamp=u'2019/07/04 20:35:41:281', msg_class=u'buffer', message=u'vlib_physmem_shared_map_create: clib_mem_create_hugetlb_fd: open: No such file or directory\n\n') log_details(_0=838, context=3, timestamp_ticks=1.6101902879480125e+159, level=<vl_api_log_level_t.VPE_API_LOG_LEVEL_WARNING: 4>, timestamp=u'2019/07/04 20:35:41:281', msg_class=u'buffer', message=u'falling back to non-hugepage backed buffer pool') test_log_dump_default (test_vpe_api.TestVpeApi) OK log_details(_0=838, context=13, timestamp_ticks=2.4954863503546518e+48, level=<vl_api_log_level_t.VPE_API_LOG_LEVEL_WARNING: 4>, timestamp=u'2019/07/04 20:35:41:281', msg_class=u'buffer', message=u'vlib_physmem_shared_map_create: clib_mem_create_hugetlb_fd: open: No such file or directory\n\n') log_details(_0=838, context=13, timestamp_ticks=1.6101902879480125e+159, level=<vl_api_log_level_t.VPE_API_LOG_LEVEL_WARNING: 4>, timestamp=u'2019/07/04 20:35:41:281', msg_class=u'buffer', message=u'falling back to non-hugepage backed buffer pool') test_log_dump_timestamp_0 (test_vpe_api.TestVpeApi) OK test_log_dump_timestamp_future (test_vpe_api.TestVpeApi) SKIP test_show_vpe_system_time_ticks (test_vpe_api.TestVpeApi) SKIP ============================================================================== TEST RESULTS: Scheduled tests: 4 Executed tests: 4 Passed tests: 2 Skipped tests: 2 ============================================================================== Test run was successful Type: feature Change-Id: I893fc0a65f39749d2091093c2c604659aadd8447 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed 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:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

/**
 * @file parc_Dictionary.h
 * @ingroup datastructures
 * @brief
 *
 * The `PARCDictionary` is a dictionary of key value tuples.
 *
 */
#ifndef libparc_parc_Dictionary_h
#define libparc_parc_Dictionary_h

#include <parc/algol/parc_ArrayList.h>

#include <stdint.h>

struct parc_dictionary;


/**
 * @typedef PARCDictionary
 * @brief  A PARCDictionary is a dictionary of key-values
 */
typedef struct parc_dictionary PARCDictionary;

/**
 * @typedef `PARCDictionary_CompareKey`
 *
 * @brief Compare two dictionary keys
 *
 * @param [in] key1 First dictionary key
 * @param [in] key2 Second dictionary key
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
typedef int (*PARCDictionary_CompareKey)(const void *key1,
                                         const void *key2);
/**
 * @typedef `PARCDictionary_ValueEquals`
 *
 * @brief Compare two values
 *
 * @param [in] value1 A pointer to the First value
 * @param [in] value2 A pointer to the Second value
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
typedef bool (*PARCDictionary_ValueEquals)(const void *value1, const void *value2);


/**
 * @typedef `PARCDictionary_KeyHashFunc`
 * @brief The key hash function must return a 32 bit hash of the key
 * @param [in] key pointer to the key to be hashed
 * @return uint32 hash
 */

typedef uint32_t (*PARCDictionary_KeyHashFunc)(const void *key);

/**
 * @typedef `PARCDictionary_FreeValue`
 * @brief The free value must free a value.
 * This will be called when a value for a key is changed.
 * It will also be used when the Dictionary is destroyed on any
 * values in the dictionary.
 * @param [in,out] value The pointer to the pointer of the value to be freed.
 */

typedef void (*PARCDictionary_FreeValue)(void **value);

/**
 * @typedef `PARCDictionary_FreeKey`
 * @brief The free key must free a key.
 * This function will be called when the value for a key is removed from the
 * dictionary. It's also called when the dictionary is destroyed.
 * @param [in,out] key  The pointer to the pointer to the key to be freed.
 */

typedef void (*PARCDictionary_FreeKey)(void **key);

/**
 * Create a Dictionary.
 * You MUST set the function to compare keys and hash keys.
 * You can give NULL as the free function of the key and the data,
 * but why would you do that? :-)
 *
 * @param [in] keyCompareFunction The function that compares 2 keys (can't be NULL)
 * @param [in] keyHashFunction The function to hash the keys to 32 bit values (can't be NULL)
 * @param [in] keyFreeFunction The function to free the key (can be NULL)
 * @param [in] valueEqualsFunction The function to know that values are equal. If NULL then values won't be compared on equality.
 * @param [in] valueFreeFunction The function to free the values (can be NULL)
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCDictionary *parcDictionary_Create(PARCDictionary_CompareKey keyCompareFunction,
                                      PARCDictionary_KeyHashFunc keyHashFunction,
                                      PARCDictionary_FreeKey keyFreeFunction,
                                      PARCDictionary_ValueEquals valueEqualsFunction,
                                      PARCDictionary_FreeValue valueFreeFunction);

/**
 * Destroy a Dictionary. If the Free functions were passed to the constructor and are not NULL
 * they will be called for every element.
 *
 * @param [in,out] dictionaryPointer A pointer to the pointer to the instance of `PARCDictionary` to be destroyed
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void parcDictionary_Destroy(PARCDictionary **dictionaryPointer);

/**
 * Set a value for a key.
 * Both key and value will be referenced by the Dictionary. No memory copies will happen.
 *
 * If the key does not exist a new dictionary entry will be added pointing to the value.
 *
 * If the key does exists then the old value will be freed using the valueFree function (if not NULL).
 * The old key will also be freed using the keyFree function (if not NULL).
 *
 * @param [in,out] dictionary A pointer to the specified `PARCDictionary`
 * @param [in] key   The key to insert in the dictionary. Can't be NULL.
 * @param [in] value The value to associate with that key. Can't be NULL.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */

void parcDictionary_SetValue(PARCDictionary *dictionary, void *key, void *value);

/**
 * Get a value from the dictionary associated with a specific key.
 *
 * @param [in] dictionary A PARCDictionary
 * @param [in] key A pointer to the key. It must be valid as a parameter to the key compare function of the
 *   dictionary
 * @return A pointer to the value.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void *parcDictionary_GetValue(PARCDictionary *dictionary, const void *key);

/**
 * Remove a value from the dictionary.  This will return the value referenced by the key. It will remove it
 *   in the process.  The key will be freed with the keyFree function (if not NULL)
 *
 * @param [in,out] dictionary A `PARCDictionary`
 * @param [in] key A pointer to the key. It must be valid as a parameter to the key compare function of the dictionary.
 * @return A pointer to the value.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void *parcDictionary_RemoveValue(PARCDictionary *dictionary, const void *key);

/**
 * Delete an entry from the dictionary.
 * This will remove an entry from the dictionary and free both the key and the value using the functions
 *   provided at the creation of the dictionary.
 *
 * @param [in,out] dictionary A pointer to an instance of `PARCDictionary`
 * @param [in] key A pointer to the key. It must be valid as a parameter to the key compare function of the dictionary.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void parcDictionary_RemoveAndDestroyValue(PARCDictionary *dictionary, const void *key);

/**
 * Get a list of the keys from this dictionary.
 *
 * @param [in] dictionary A `PARCDictionary`
 * @return A pointer to a {@link PARCArrayList} of (pointers to) keys.  All of these keys will be valid keys in the dictionary.
 * The caller will own the list of keys and should destroy it when done.  The caller will not own
 * the key themselves. (Destroying the `PARCArrayList` should be enough).
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCArrayList *parcDictionary_Keys(const PARCDictionary *dictionary);

/**
 * Get a list of the values from this dictionary.
 * The caller will own the list of values and should destroy it when done.  The caller will not own
 * the values themselves. Destroying the {@link PARCArrayList} should be enough.
 *
 * Note that if the Dictionary is destroyed the value pointers might no longer point to valid values.
 *
 * @param [in] dictionary A pointer to an instance of `PARCDictionary`
 * @return A pointer to a `PARCArrayList` of (pointers to) values.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCArrayList *parcDictionary_Values(const PARCDictionary *dictionary);

/**
 * Return the number of entries in the dictionary.
 *
 * @param [in] dictionary A pointer to an instance of `PARCDictionary`
 * @return The number of keys in the dictionary.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
size_t parcDictionary_Size(const PARCDictionary *dictionary);


/**
 * Determine if two `PARCDictionary` instances are equal.
 *
 * Two `PARCDictionary` instances are equal if, and only if, the trees are equal
 *
 * The following equivalence relations on non-null `PARCDictionary` instances are maintained:
 *
 *  * It is reflexive: for any non-null reference value x, `PARCDictionary_Equals(x, x)`
 *      must return true.
 *
 *  * It is symmetric: for any non-null reference values x and y,
 *    `parcDictionary_Equals(x, y)` must return true if and only if
 *        `parcDictionary_Equals(y, x)` returns true.
 *
 *  * It is transitive: for any non-null reference values x, y, and z, if
 *        `parcDictionary_Equals(x, y)` returns true and
 *        `parcDictionary_Equals(y, z)` returns true,
 *        then  `parcDictionary_Equals(x, z)` must return true.
 *
 *  * It is consistent: for any non-null reference values x and y, multiple
 *      invocations of `parcDictionary_Equals(x, y)` consistently return true or
 *      consistently return false.
 *
 *  * For any non-null reference value x, `parcDictionary_Equals(x, NULL)` must
 *      return false.
 *
 * @param [in] dictionary1 A pointer to a `PARCDictionary` instance.
 * @param [in] dictionary2 A pointer to a `PARCDictionary` instance.
 * @return true if the two `PARCDictionary` instances are equal.
 *
 * Example:
 * @code
 * {
 *    PARCDictionary *a = parcDictionary_Create();
 *    PARCDictionary *b = parcDictionary_Create();
 *
 *    if (parcDictionary_Equals(a, b)) {
 *        // true
 *    } else {
 *        // false
 *    }
 * }
 * @endcode
 */
int parcDictionary_Equals(const PARCDictionary *dictionary1, const PARCDictionary *dictionary2);
#endif // libparc_parc_Dictionary_h