summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2016-10-13json: Check party id name, number, subaddresses for UTF-8.Richard Mudgett
* Updated unit test as ast_json_name_number() is now NULL tolerant. ASTERISK-26466 #close Reported by: Richard Mudgett Change-Id: I7d4e14194f8f81f24a1dc34d1b8602c0950265a6
2016-08-17res_ari: Add http prefix to generated docsTorrey Searle
updated the uri handler to include the url prefix of the http server this enables res_ari to add it to the uris when generating docs Change-Id: I279335a2625261a8492206c37219698f42591c2e
2016-07-07res_sorcery_realtime: fix bug when successful UPDATE is treated as failedAlexei Gradinari
If the SQL UPDATE statement changes nothing then SQLRowCount returns 0. This value should be treated as success. But the function sorcery_realtime_update treats it as failed. This bug was found using stress tests on PJSIP. If there are 2 consecutive SIP REGISTER requests with the same contact data during 1 second then res_pjsip_registrar adds contact location on 1st request and tries to update contact location on 2nd. The update fails and res_pjsip_registrar even removes correct contact location. The test "object_update_uncreated" was removed from test_sorcery_realtime.c because it's now a valid situation. This patch also adds missing debug of extra SQL parameter. ASTERISK-26172 #close Change-Id: I05a7f3051455336c9dda29efc229decf86071303
2016-06-22test_res_pjsip_scheduler: Add 'depends' on pjproject in MODULEINFOGeorge Joseph
Since the file was missing the depends on pjproject, it wasn't picking up the pjproject related include path. If there was no system installed pjproject and pjproject-bundled was used, a compile would fail because pjsip.h wasn't found. ASTERISK-26139 #close Change-Id: I2ee64a999051452bc198c4e2c168c70769cd3757
2016-06-10Merge "cel: Ensure only one dial status per channel exists." into 13Joshua Colp
2016-06-09cel: Ensure only one dial status per channel exists.Joshua Colp
CEL wrongly assumed that a channel would only have a single dial event on it. This is incorrect. Particularly in a queue each call attempt to a member will result in a dial event, adding a new dial status in CEL without removing the old one. This would cause the container to grow with only one dial status being removed when the channel went away. The other dial status entries would remain leaking memory. This change fixes the memory leak by ensuring that only one dial status will only ever exist for each channel. The behavior during the scenario where multiple events are received has also been improved. For failure cases the first failure will be the dial status. If an answer dial status is received, though, it will take priority and the dial status for the channel will be answer. Memory usage has also been decreased by storing the minimal amount of information and the code has been cleaned up slightly. ASTERISK-25262 #close Change-Id: I5944eb923db17b6a0faa7317ff6abc9307c009fe
2016-06-09build: Fix ast_sockaddr initialization to be more portableGeorge Joseph
A change to glibc 2.22 changed the order of the sockadddr_storage members which caused the places where we do an initialization of ast_sockaddr with '{ { 0, 0, } }' to fail compilation. Those initializers (which we shouldn't have been using anyway) have been replaced with memsets. Change-Id: Idd1b3b320903d8771bfe221f0b015685de628fa4
2016-04-27Merge "config: Fix ast_config_text_file_save2 writability check for missing ↵Joshua Colp
files" into 13
2016-04-27Merge "res_pjsip: Add serialized scheduler (res_pjsip/pjsip_scheduler.c)" ↵Joshua Colp
into 13
2016-04-25config: Fix ast_config_text_file_save2 writability check for missing filesGeorge Joseph
A patch I did back in 2014 modified ast_config_text_file_save2 to check the writability of the main file and include files before truncating and re-writing them. An unintended side-effect of this was that if a file doesn't exist, the check fails and the write is aborted. This patch causes ast_config_text_file_save2 to check the writability of the parent directory of missing files instead of checking the file itself. This allows missing files to be created again. A unit test was also added to test_config to test saving of config files. The regression was discovered when app_voicemail's passwordlocation=spooldir feature stopped working. ASTERISK-25917 #close Reported-by: Jonathan Rose Change-Id: Ic4dbe58c277a47b674679e49daed5fc6de349f80
2016-04-22test_message.c: Wait longer in case dialplan also processes the test message.Richard Mudgett
Bumped the wait from 1 second to 5 seconds. The test message was hitting my default call handler and failing the test because it took longer. Change-Id: I3a03737f25e92983de00548fcc7bbc50dd7544ba
2016-04-22bridge_softmix.c: Fix crash if channel fails to join mixing tech.Richard Mudgett
softmix_bridge_join() failed because of an allocation failure. To address this, the softmix bridge technology now checks if the channel failed to join softmix successfully. In addition, the bridge now begins the process of kicking the channel out of the bridge so we don't have channels partially in the bridge for very long. * Fix the test_channel_feature_hooks.c unit tests. The test channel must have a valid codec to join the simple_bridge technology. This patch makes joining a bridge more strict by not allowing partially joined channels to remain in the bridge. Change-Id: I97e2ade6a2bcd1214f24fb839fda948825b61a2b
2016-04-14res_pjsip: Add serialized scheduler (res_pjsip/pjsip_scheduler.c)George Joseph
There are several places that do scheduled tasks or periodic housecleaning, each with its own implementation: * res_pjsip_keepalive has a thread that sends keepalives. * pjsip_distributor has a thread that cleans up expired unidentified requests. * res_pjsip_registrar_expire has a thread that cleans up expired contacts. * res_pjsip_pubsub uses ast_sched directly and then calls ast_sip_push_task. * res_pjsip_sdp_rtp also uses ast_sched to send keepalives. There are also places where we should be doing scheduled work but aren't. A good example are the places we have sorcery observers to start registration or qualify. These don't work when changes are made to a backend database without a pjsip reload. We need to check periodically. As a first step to solving these issues, a new ast_sip_sched facility has been created. ast_sip_sched wraps ast_sched but only uses ast_sched as a scheduled queue. When a task is ready to run, ast_sip_task_pusk is called for it. This ensures that the task is executed in a PJLIB registered thread and doesn't hold up the ast_sched thread so it can immediately continue processing the queue. The serializer used by ast_sip_sched is one of your choosing or a random one from the res_pjsip pool if you don't choose one. Another feature is the ability to automatically clean up the task_data when the task expires (if ever). If it's an ao2 object, it will be dereferenced, if it's a malloc'd object it will be freed. This is selectable when the task is scheduled. Even if you choose to not auto dereference an ao2 task data object, the scheduler itself maintains a reference to it while the task is under it's control. This prevents the data from disappearing out from under the task. There are two scheduling models. AST_SIP_SCHED_TASK_PERIODIC specifies that the invocations of the task occur at the specific interval. That is, every "interval" milliseconds, regardless of how long the task takes. If the task takes longer than the interval, it will be scheduled at the next available multiple of interval. For exmaple: If the task has an interval of 60 secs and the task takes 70 secs (it better not), the next invocation will happen at 120 seconds. AST_SIP_SCHED_TASK_DELAY specifies that the next invocation of the task should start "interval" milliseconds after the current invocation has finished. Also, the same ast_sched facility for fixed or variable intervals exists. The task's return code in conjunction with the AST_SIP_SCHED_TASK_FIXED or AST_SIP_SCHED_TASK_VARIABLE flags controls the next invocation start time. One res_pjsip.h housekeeping change was made. The pjsip header files were added to the top. There have been a few cases lately where I've needed res_pjsip.h just for ast_sip calls and had compiles fail spectacularly because I didn't add the pjsip header files to my source even though I never referenced any pjsip calls. Finally, a few new convenience APIs were added to astobj2 to make things a little easier in the scheduler. ao2_ref_and_lock() calls ao2_ref() and ao2_lock() in one go. ao2_unlock_and_unref() does the reverse. A few macros were also copied from res_phoneprov because I got tired of having to duplicate the same hash, sort and compare functions over and over again. The AO2_STRING_FIELD_(HASH|SORT|CMP)_FN macros will insert functions suitable for aor_container_alloc into your source. This facility can be used immediately for the situations where we already have a thread that wakes up periodically or do some scheduled work. For the registration and qualify issues, additional sorcery and schema changes would need to be made so that we can easily detect changed objects on a periodic basis without having to pull the entire database back to check. I'm thinking of a last-updated timestamp on the rows but more on this later. Change-Id: I7af6ad2b2d896ea68e478aa1ae201d6dd016ba1c
2016-04-08lock: Add named lock capabilityGeorge Joseph
Locking some objects like sorcery objects can be tricky because the underlying ao2 object may not be the same for all callers. For instance, two threads that call ast_sorcery_retrieve_by_id on the same aor name might actually get 2 different ao2 objects if the underlying wizard had to rehydrate the aor from a database. Locking one ao2 object doesn't have any effect on the other even if those objects had locks in the first place. Named locks allow access control by keyspace and key strings. Now an "aor" named "1000" can be locked and any other thread attempting to lock "aor" "1000" will wait regardless of whether the underlying ao2 object is the same or not. Mutex and rwlocks are supported. This capability will initially be used to lock an aor when multiple threads may be attempting to prune expired contacts from it. Change-Id: If258c0b7f92b02d07243ce70e535821a1ea7fb45
2016-04-04stringfields: Refactor to allow fields to be added to the end of structuresGeorge Joseph
String fields are great, except that you can't add new ones without breaking ABI compatibility because it shifts down everything else in the structure. The only alternative is to add your own char * field to the end of the structure and manage the memory yourself which isn't ideal, especially since you then can't use the OPT_STRINGFIELD_T type. Background: The reason string fields had to be declared inside the AST_DECLARE_STRING_FIELDS block was to facilitate iteration over all declared fields for initialization, compare and copy. Since AST_DECLARE_STRING_FIELDS declared the pool, then the fields, then the manager, you could use the offsets of the pool and manager and iterate over the sequential addresses in between to access the fields. The actual pool, field allocation and field set operations don't actually care where the field is. It's just iteration over the fields that was the problem. Solution: Extended String Fields An extended string field is one that is declared outside the AST_DECLARE_STRING_FIELDS block but still (anywhere) inside the parent structure. Other than using AST_STRING_FIELD_EXTENDED instead of AST_STRING_FIELD, it looks the same as other string fields. It's storage comes from the pool and it participates in string field compare and copy operations peformed on the parent structure. It's also a valid target for the OPT_STRINGFIELD_T aco option type. Implementation: To keep track of the extended fields and make sure that ABI isn't broken, the existing embedded_pool pointer in the manager structure was repurposed to be a pointer to a separate header structure that contains the embedded_pool pointer plus a vector of fields. The length of the manager structure didn't change and the embedded_pool pointer isn't used in the macros, only the stringfields C code. A side benefit of this is that changing the header structure in the future won't break ABI. ast_string_fields_init initializes the normal string fields and appends them to the vector, and subsequent calls to ast_string_field_init_extended initialize and append the extended fields. Cleanup, ast_string_fields_cmp, and ast_string_fields_copy can now work on the vector instead of sequentially traversing the addresses between the pool and manager. The total size of a structure using string fields didn't change, whether using extended fields or not, nor have the offsets of any structure members, either inside the original block or outside. Adding an extended field to the end of a structure is the same as adding a char *. Details: The stringfield C code was pulled out from utils.c and into stringfields.c. It just made sense. Additional work was done in ast_string_field_init and ast_calloc_with_stringfields to handle the allocation of the new header structure and the vector, and the associated cleanup. In the process some additional NULL pointer checking was added. A lot of work was done in stringfields.h since the logic for compare and copy is there. Documentation was added as well as somne additional NULL checking. The ability to call ast_calloc_with_stringfields with a number of structures greater than 1 never really worked. Well, the calloc worked but there was no way to access the additional structures or clean them up. It was agreed that there was no use case for requesting more than 1 structure so an ast_assert was added to prevent it and the iteration code removed. Testing: The stringfield unit tests were updated to test both normal and extended fields. Tests for ast_string_field_ptr_set_by_fields and ast_calloc_with_stringfields were also added. As an ABI test, 13 was compiled from git and the res_pjsip_* modules, except res_pjsip itself, saved off. The patch was then added and a full compile and install was performed. Then the older res_pjsip_* moduled were copied over the installed versions so res_pjsip was new and the rest were old. No issues. contact->aor, which is a char * at the end of contact, was then changed to an extended string field and a recompile and reinstall was performed, again leaving stock versions of the the res_pjsip_* modules. Again, no issues with the res_pjsip_* modules using the old stringfield implementation and with contact->aor as a char *, and res_pjsip itself using the new stringfield implementation and contact->aor being an extended string field. Finally, several existing string fields were converted to extended string fields to test OPT_STRINGFIELD_T. Again, no issues. Change-Id: I235db338c5b178f5a13b7946afbaa5d4a0f91d61
2016-03-25sorcery/res_pjsip: Refactor for realtime performanceGeorge Joseph
There were a number of places in the res_pjsip stack that were getting all endpoints or all aors, and then filtering them locally. A good example is pjsip_options which, on startup, retrieves all endpoints, then the aors for those endpoints, then tests the aors to see if the qualify_frequency is > 0. One issue was that it never did anything with the endpoints other than retrieve the aors so we probably could have skipped a step and just retrieved all aors. But nevermind. This worked reasonably well with local config files but with a realtime backend and thousands of objects, this was a nightmare. The issue really boiled down to the fact that while realtime supports predicates that are passed to the database engine, the non-realtime sorcery backends didn't. They do now. The realtime engines have a scheme for doing simple comparisons. They take in an ast_variable (or list) for matching, and the name of each variable can contain an operator. For instance, a name of "qualify_frequency >" and a value of "0" would create a SQL predicate that looks like "where qualify_frequency > '0'". If there's no operator after the name, the engines add an '=' so a simple name of "qualify_frequency" and a value of "10" would return exact matches. The non-realtime backends decide whether to include an object in a result set by calling ast_sorcery_changeset_create on every object in the internal container. However, ast_sorcery_changeset_create only does exact string matches though so a name of "qualify_frequency >" and a value of "0" returns nothing because the literal "qualify_frequency >" doesn't match any name in the objset set. So, the real task was to create a generic string matcher that can take a left value, operator and a right value and perform the match. To that end, strings.c has a new ast_strings_match(left, operator, right) function. Left and right are the strings to operate on and the operator can be a string containing any of the following: = (or NULL or ""), !=, >, >=, <, <=, like or regex. If the operator is like or regex, the right string should be a %-pattern or a regex expression. If both left and right can be converted to float, then a numeric comparison is performed, otherwise a string comparison is performed. To use this new function on ast_variables, 2 new functions were added to config.c. One that compares 2 ast_variables, and one that compares 2 ast_variable lists. The former is useful when you want to compare 2 ast_variables that happen to be in a list but don't want to traverse the list. The latter will traverse the right list and return true if all the variables in it match the left list. Now, the backends' fields_cmp functions call ast_variable_lists_match instead of ast_sorcery_changeset_create and they can now process the same syntax as the realtime engines. The realtime backend just passes the variable list unaltered to the engine. The only gotcha is that there's no common realtime engine support for regex so that's been noted in the api docs for ast_sorcery_retrieve_by_fields. Only one more change to sorcery was done... A new config flag "allow_unqualified_fetch" was added to reg_sorcery_realtime. "no": ignore fetches if no predicate fields were supplied. "error": same as no but emit an error. (good for testing) "yes": allow (the default); "warn": allow but emit a warning. (good for testing) Now on to res_pjsip... pjsip_options was modified to retrieve aors with qualify_frequency > 0 rather than all endpoints then all aors. Not only was this a big improvement in realtime retrieval but even for config files there's an improvement because we're not going through endpoints anymore. res_pjsip_mwi was modified to retieve only endpoints with something in the mailboxes field instead of all endpoints then testing mailboxes. res_pjsip_registrar_expire was completely refactored. It was retrieving all contacts then setting up scheduler entries to check for expiration. Now, it's a single thread (like keepalive) that periodically retrieves only contacts whose expiration time is < now and deletes them. A new contact_expiration_check_interval was added to global with a default of 30 seconds. Ross Beer reports that with this patch, his Asterisk startup time dropped from around an hour to under 30 seconds. There are still objects that can't be filtered at the database like identifies, transports, and registrations. These are not going to be anywhere near as numerous as endpoints, aors, auths, contacts however. Back to allow_unqualified_fetch. If this is set to yes and you have a very large number of objects in the database, the pjsip CLI commands will attempt to retrive ALL of them if not qualified with a LIKE. Worse, if you type "pjsip show endpoint <tab>" guess what's going to happen? :) Having a cache helps but all the objects will have to be retrieved at least once to fill the cache. Setting allow_unqualified_fetch=no prevents the mass retrieve and should be used on endpoints, auths, aors, and contacts. It should NOT be used for identifies, registrations and transports since these MUST be retrieved in bulk. Example sorcery.conf: [res_pjsip] endpoint=config,pjsip.conf,criteria=type=endpoint endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error ASTERISK-25826 #close Reported-by: Ross Beer Tested-by: Ross Beer Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-15sched.c: Ensure oldest expiring entry runs first.Richard Mudgett
This patch is part of a series to resolve deadlocks in chan_sip.c. * Updated sched unit test to check new behavior. ASTERISK-25023 Change-Id: Ib69437327b3cda5e14c4238d9ff91b2531b34ef3
2016-02-18Fix failing threadpool_auto_increment test.Mark Michelson
The threadpool_auto_increment test fails infrequently for a couple of reasons * The threadpool listener was notified of fewer tasks being pushed than were actually pushed * The "was_empty" flag was set to an unexpected value. The problem is that the test pushes three tasks into the threadpool. Test expects the threadpool to essentially gather those three tasks, and then distribute those to the threadpool threads. It also expects that as the tasks are pushed in, the threadpool listener is alerted immediately that the tasks have been pushed. In reality, a task can be distributed to the threadpool threads quicker than expected, meaning that the threadpool has already emptied by the time each subsequent task is pushed. In addition, the internal threadpool queue can be delayed so that the threadpool listener is not alerted that a task has been pushed even after the task has been executed. From the test's point of view, there's no way to be able to predict exactly the order that task execution/listener notifications will occur, and there is no way to know which listener notifications will indicate that the threadpool was previously empty. For this reason, the test has been updated to only check the things it can check. It ensures that all tasks get executed, that the threads go idle after the tasks are executed, and that the listener is told the proper number of tasks that were pushed. Change-Id: I7673120d74adad64ae6894594a606e102d9a1f2c
2016-02-09tests/test_sorcery_memory_cache_thrash: Improve termination process.Joshua Colp
When terminating the threads thrashing a sorcery memory cache each would be told to stop and then we would wait on them. During at least one thrashing test this was problematic due to the specific usage pattern in use. It would take some time for termination of the thread to occur. This would occur due to contention between the threads retrieving and the threads updating the cache. As the retrieving threads are given priority it may be some time before the updating threads are able to proceed. This change makes it so all threads are told to stop and then each are joined to ensure they stop. This way all the threads should stop at around the same time instead of waiting for one to stop, the next to stop, then the next, and so on. As a result of this the execution time for each thrash test is much closer to their expected value than previously seen as well. Change-Id: I04a53470b0ea4170b8819180b0bd7475f3642827
2016-02-03logging: Remove/fix some message annoyancesGeorge Joseph
test_dlinklists doesn't need to NOTICE everyone that every macro worked. res_phoneprov doesn't need to VERBOSE everyone that a phoneprov extension or provider was registered. res_odbc was missing a newline at the end of one message. Change-Id: I6c06361518ef3711821795e535acd439782a995e
2016-01-19test_threadpool: Wait for each task to complete and fix memory leak.Joshua Colp
This change makes the thread_timeout_thrash unit test wait for each task to complete. This fixes the problem where the test would prematurely end when all threads were gone and a new one had to be started to handle the last task. It also increases the thrasing as it is now more likely for each task to encounter the above scenario. This also fixes a memory leak where the data for each task was not being freed. ASTERISK-25611 #close Change-Id: I5017d621a4dc911f509074c16229b86bff2fb3c6
2016-01-12res_sorcery_realtime: Remove leading ^ requirement.Mark Michelson
res_sorcery_realtime's search-by-regex callback performed a check to ensure that the passed-in regex began with a caret (^). If it did not, then no results would be returned. This callback only started to become used when "like" support was added to PJSIP CLI commands. The CLI command for listing objects would pass an empty regex ("") to the sorcery backend if no "like" statement was present. For most sorcery backends, this resulted in returning all objects. However, for realtime, this resulted in returning no objects. This commit seeks to fix the regression by removing the requirement from res_sorcery_realtime for the passed-in-regex to begin with a caret. ASTERISK-25689 #close Reported by Marcelo Terres Change-Id: I22b4dc5d7f3f11bb29ac2e42ef94682e9bab3b20
2015-12-28tests/test_stasis_endpoints: Remove expected duplicate eventsMatt Jordan
The cache_clear test was written to expect duplicate Stasis messages sent from the technology endpoint to the all caching topic. This patch fixes the test to no longer expect these duplicate messages. ASTERISK-25137 Change-Id: I58075d70d6cdf42e792e0fb63ba624720bfce981
2015-11-12format_cap: Don't append the 'none' format when appending all.Joshua Colp
When appending all formats of a type all the codecs are iterated and added. This operation was incorrectly adding the ast_format_none format which is special in that it is supposed to be used when no format is present. It shouldn't be appended. ASTERISK-25535 Change-Id: I7b00f3bdf4a5f3022e483d6ece602b1e8b12827c
2015-11-11threadpool: Handle worker thread transitioning to dead when going active.Joshua Colp
This change adds handling of dead worker threads when moving them to be active. When this happens the worker thread is removed from both the active and idle threads container. If no threads are able to be moved to active then the pool grows as configured. A unit test has also been added which thrashes the idle timeout and thread activation to exploit any race conditions between the two. ASTERISK-25546 #close Change-Id: I6c455f9a40de60d9e86458d447b548fb52ba1143
2015-11-09ast_format_cap_get_names: To display all formats, the buffer was increased.Alexander Traud
ASTERISK-25533 #close Change-Id: Ie1a9d1a6511b3f1a56b93d04475fbf8a4e40010a
2015-08-09main/format: Add an API call for retrieving format attributesMatt Jordan
Some codecs that may be a third party library to Asterisk need to have knowledge of the format attributes that were negotiated. Unfortunately, when the great format migration of Asterisk 13 occurred, that ability was lost. This patch adds an API call, ast_format_attribute_get, to the core format API, along with updates to the unit test to check the new API call. A new callback is also now available for format attribute modules, such that they can provide the format attribute values they manage. Note that the API returns a void *. This is done as the format attribute modules themselves may store format attributes in any particular manner they like. Care should be taken by consumers of the API to check the return value before casting and dereferencing. Consumers will obviously need to have a priori knowledge of the type of the format attribute as well. Change-Id: Ieec76883dfb46ecd7aff3dc81a52c81f4dc1b9e3
2015-07-15strings.h: Fix issues with escape string functions.Richard Mudgett
Fixes for issues with the ASTERISK-24934 patch. * Fixed ast_escape_alloc() and ast_escape_c_alloc() if the s parameter is an empty string. If it were an empty string the functions returned NULL as if there were a memory allocation failure. This failure caused the AMI VarSet event to not get posted if the new value was an empty string. * Fixed dest buffer overwrite potential in ast_escape() and ast_escape_c(). If the dest buffer size is smaller than the space needed by the escaped s parameter string then the dest buffer would be written beyond the end by the nul string terminator. The num parameter was really the dest buffer size parameter so I renamed it to size. * Made nul terminate the dest buffer if the source string parameter s was an empty string in ast_escape() and ast_escape_c(). * Updated ast_escape() and ast_escape_c() doxygen function description comments to reflect reality. * Added some more unit test cases to /main/strings/escape to cover the empty source string issues. ASTERISK-25255 #close Reported by: Richard Mudgett Change-Id: Id77fc704600ebcce81615c1200296f74de254104
2015-07-11Merge "tests/test_devicestate: Add additional tests for the device state ↵Matt Jordan
API" into 13
2015-07-11tests/test_devicestate: Add additional tests for the device state APIMatt Jordan
This patch adds more tests that exercise the device state API. This includes: * Tests that cover adding a device state provider, as well as deleting a device state provider. This also verifies that you cannot add an already added device state provider, and cannot delete an already deleted device state provider. * A test that covers changing device state and receiving said updates from a device state subscriber. This also covers hitting both the device state cache as well as a custom device state provider. * A test that covers converting device state to channel state and device state values to a string representation and back. * A test that covers obtaining device state from an active channel and a channel driver that provides its own device state. Change-Id: I2adca67ffb405cd8625a5d6df1e3f9b3d945c08d
2015-07-10tests/test_sorcery_memory_cache_thrash: Fix test loading problemsMatt Jordan
Because unit tests now want descriptions to not end with a newline, the sorcery memory cache thrash tests failed to register. This patch corrects their descriptions. Change-Id: Id004b1becfdeed8ee3c846f49beab76a5c0f68b6
2015-07-09res_sorcery_memory_cache: Backport to 13Joshua Colp
Gerrit is complaining of conflicts when trying to create a patch series of all of the cherry-picked master commits, so I have instead squashed it all into one commit. ASTERISK-25067 #close Reported by: Matt Jordan Change-Id: I6dda90343fae24a75dc5beec84980024e8d61eb9
2015-06-24Unit tests: Fix unit test description strings.Richard Mudgett
Analyzing the code shows that the unit test summary and description strings should not end with a new-line character. Where these strings are used in the code a new-line is provided for output. Change-Id: I129284f5e7ca93d82532334076da4c462d3d9fba
2015-06-09Merge "Fix unsafe uses of ast_context pointers." into 13Matt Jordan
2015-06-08Fix unsafe uses of ast_context pointers.Corey Farrell
Although ast_context_find, ast_context_find_or_create and ast_context_destroy perform locking of the contexts table, any context pointer can become invalid at any time that the contexts table is unlocked. This change adds locking around all complete operations involving these functions. Places where ast_context_find was followed by ast_context_destroy have been replaced with calls ast_context_destroy_by_name. ASTERISK-25094 #close Reported by: Corey Farrell Change-Id: I1866b6787730c9c4f3f836b6133ffe9c820734fa
2015-06-03AMI: Escape string values.Kevin Harwell
So this issue is a bit complicated. Since it is possible to pass values to AMI that contain a '\r\n' (or other similar sequences) these values need to be escaped. One way to solve this is to escape the values and then pass the escaped values to the AMI variable parameter string building function. However, this puts the onus on the pre-build function to escape all string values. This potentially requires a fair amount of changes along with a lot of string allocations/freeing for all values. Surely there is a way to push this complexity down a level into the string building function itself? This of course is possible, but ends up requiring a way to distinguish between strings that need to be escaped and those that don't. The best way to handle this is by introducing a new format specifier in the format string. For instance a %s (no escape) and %S (escape). However, that is a bit weird and unexpected. So faced with those possibilities this patch implements a limited version of the first option. Instead of attempting to escape all string values this patch only escapes those values that make sense. This approach limits the number of changes and doesn't suffer from the odd format specifier problem. ASTERISK-24934 #close Reported by: warren smith Change-Id: Ib55a5b84fe0481b0f2caaaab68c566f392c0aac0
2015-05-20Merge "Fix potential crash after unload of func_periodic_hook or ↵Matt Jordan
test_message." into 13
2015-05-15res_pjsip_config_wizard/config: Fix template processingGeorge Joseph
The config wizard was always pulling the first occurrence of a variable from an ast_variable list but this gets the template value from the list instead of any overridden value. This patch creates ast_variable_find_last_in_list() in config.c and updates res_pjsip_config_wizard to use it instead of ast_variable_find_in_list. Now the overridden values, where they exist, are used instead of template variables. Updated test_config to test the new API. ASTERISK-25089 #close Reported-by: George Joseph <george.joseph@fairview5.com> Tested-by: George Joseph <george.joseph@fairview5.com> Change-Id: Ifa7ddefc956a463923ee6839dd1ebe021c299de4
2015-05-14Fix potential crash after unload of func_periodic_hook or test_message.Corey Farrell
These modules save a pointer to the context they create on load, and use that pointer to destroy the context at unload. It is not safe to save this pointer, it is replaced during load of pbx_config, pbx_lua or pbx_ael. This change causes the modules to pass NULL to ast_context_destroy, a safer way to perform the unregistration since it does not use a pointer that could become invalid. ASTERISK-25085 #close Reported by: Corey Farrell Change-Id: I6a00ec8e38046058f97dc703e1adcde9bf517835
2015-05-12sorcery: Add API to insert/remove a wizard to/from an object type's listGeorge Joseph
Currently you can 'apply' a wizard to an object type but the wizard always goes at the end of the object type's wizard list. This patch adds a new ast_sorcery_insert_wizard_mapping function that allows you to insert a wizard anyplace in the list. I.E. You could add a caching wizard to an object type and place it before all wizards. ast_sorcery_get_wizard_mapping_count and ast_sorcery_get_wizard_mapping were added to allow examination of the mapping list. ast_sorcery_remove_mapping was added to remove a mapping by name. As part of this patch, the object type's wizard list was converted from an ao2_container to an AST_VECTOR_RW. A new test was added to test_sorcery for this capability. ASTERISK-25044 #close Change-Id: I9d2469a9296b2698082c0989e25e6848dc403b57
2015-05-11vector: Add REMOVE, ADD_SORTED and RESET macrosGeorge Joseph
Based on feedback from Corey Farrell and Y Ateya, a few new macros have been added... AST_VECTOR_REMOVE which takes a parameter to indicate if order should be preserved. AST_VECTOR_ADD_SORTED which adds an element to a sorted vector. AST_VECTOR_RESET which cleans all elements from the vector leaving the storage intact. Change-Id: I41d32dbdf7137e0557134efeff9f9f1064b58d14
2015-05-06vector: Additional enhancements and fixesGeorge Joseph
After using the new vector stuff for real I found... A bug in AST_VECTOR_INSERT_AT that could cause a seg fault. The callbacks needed to be closer to ao2_callback in behavior WRT to CMP_MATCH and CMP_STOP behavior and the ability to return a vector of matched entries. A pre-existing issue with APPEND and REPLACE was also fixed. I also added a new macro to test.h that acts like ast_test_validate but also accepts a return code variable and a cleanup label. As well as printing the error, it sets the rc variable to AST_TEST_FAIL and does a goto to the specified label on error. I had a local version of this in test_vector so I just moved it. ASTERISK-25045 Change-Id: I05e5e47fd02f61964be13b7e8942bab5d61b29cc
2015-05-05test_vector: Fix build breakage caused by ASTERISK_REGISTER_FILEGeorge Joseph
My 13 version of test_vector had an ASTERISK_REGISTER_FILE() macro call at the top which is only supported in master. Once removed builds are successful. Change-Id: I7cac8b669bed6de543bbf4e2eec3cffc9741acdd
2015-05-04vector: Traversal, retrieval, insert and locking enhancementsGeorge Joseph
Renamed AST_VECTOR_INSERT to AST_VECTOR_REPLACE because it really does replace not insert. The few users of AST_VECTOR_INSERT were refactored. Because these are macros, there should be no ABI compatibility issues. Added AST_VECTOR_INSERT_AT that actually inserts an element into the vector at a specific index pushing existing elements to the right. Added AST_VECTOR_GET_CMP that can retrieve from the vector based on a user-provided compare function. Added AST_VECTOR_CALLBACK function that will execute a function for each element in the vector. Similar to ao2_callback and ao2_callback_data functions although the vector callback can take a variable number of arguments. This should allow easy migration to a vector where a container might be too heavy. Added read/write locked vector and lock manipulation macros. Added unit tests. ASTERISK-25045 #close Change-Id: I2e07ecc709d2f5f91bcab8904e5e9340609b00e0
2015-04-11clang compiler warnings: Fix various warnings for testsMatthew Jordan
This patch fixes a variety of clang compiler warnings for unit tests. This includes autological comparison issues, ignored return values, and interestingly enough, one embedded function. Fun! Review: https://reviewboard.asterisk.org/r/4555 ASTERISK-24917 Reported by: dkdegroot patches: rb4555.patch submitted by dkdegroot (License 6600) ........ Merged revisions 434705 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@434706 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-03-19funcs/func_env: Fix regression caused in FILE read operationMatthew Jordan
When r432935 was merged, it did correctly fix a situation where a FILE read operation on the middle of a file buffer would not read the requested length in the parameters passed to the FILE function. Unfortunately, it would also allow the FILE function to append more bytes than what was available in the buffer if the length exceeded the end of the buffer length. This patch takes the minimum of the remaining bytes in the buffer along with the calculated length to append provided by the original patch, and uses that as the length to append in the return result. This patch also updates the unit tests with the scenarios that were originally pointed out in ASTERISK-21765 that the original implementation treated incorrectly. ASTERISK-21765 ........ Merged revisions 433173 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@433174 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07func_config: Add ability to retrieve specific occurrence of a variableGeorge Joseph
I guess nobody uses templates with AST_CONFIG because today if you have a context that inherits from a template and you call AST_CONFIG on the context, you'll get the value from the template even if you've overridden it in the context. This is because AST_CONFIG only gets the first occurrence which is always from the template. This patch adds an optional 'index' parameter to AST_CONFIG which lets you specify the exact occurrence to retrieve, or '-1' to retrieve the last. The default behavior is the current behavior. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4313/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@430315 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-23test_astobj2: Fix warning for missing trailing slash in categoryGeorge Joseph
This patch adds a trailing slash to the category for this test. No more warning. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4295/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@430059 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-11Stasis: Update unittest for channel snapshotsKinsey Moore
This adjusts the unit test for channel snapshots to take the new language key into account. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@429352 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-05sorcery: Add additional observer capabilities.George Joseph
Add new global, instance and wizard observers. instance_created wizard_registered wizard_unregistered instance_destroying instance_loading instance_loaded wizard_mapped object_type_registered object_type_loading object_type_loaded wizard_loading wizard_loaded Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4215/ ........ Merged revisions 428999 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@429000 65c4cc65-6c06-0410-ace0-fbb531ad65f3