[libvirt PATCH 11/17] tests: Mock virProcessGetMaxMemLock()

Andrea Bolognani posted 17 patches 4 years, 11 months ago
[libvirt PATCH 11/17] tests: Mock virProcessGetMaxMemLock()
Posted by Andrea Bolognani 4 years, 11 months ago
Up until now we've implicitly relied on the fact that failures
reported from this function were simply ignored, but that's
about to change and so we need a proper mock.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/util/virprocess.h  | 2 +-
 tests/virprocessmock.c | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 34210d6c9d..dbf4148e90 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -79,7 +79,7 @@ int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
 int virProcessSetMaxFiles(pid_t pid, unsigned int files);
 int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
 
-int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes);
+int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) G_GNUC_NO_INLINE;
 
 /* Callback to run code within the mount namespace tied to the given
  * pid.  This function must use only async-signal-safe functions, as
diff --git a/tests/virprocessmock.c b/tests/virprocessmock.c
index c9386d757a..0356ff2f70 100644
--- a/tests/virprocessmock.c
+++ b/tests/virprocessmock.c
@@ -21,6 +21,13 @@
 #include <config.h>
 #include "virprocess.h"
 
+int
+virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long *bytes G_GNUC_UNUSED)
+{
+    *bytes = 0;
+    return 0;
+}
+
 int
 virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long bytes G_GNUC_UNUSED)
 {
-- 
2.26.2

Re: [libvirt PATCH 11/17] tests: Mock virProcessGetMaxMemLock()
Posted by Michal Privoznik 4 years, 11 months ago
On 3/5/21 8:13 PM, Andrea Bolognani wrote:
> Up until now we've implicitly relied on the fact that failures
> reported from this function were simply ignored, but that's
> about to change and so we need a proper mock.
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>   src/util/virprocess.h  | 2 +-
>   tests/virprocessmock.c | 7 +++++++
>   2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virprocess.h b/src/util/virprocess.h
> index 34210d6c9d..dbf4148e90 100644
> --- a/src/util/virprocess.h
> +++ b/src/util/virprocess.h
> @@ -79,7 +79,7 @@ int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
>   int virProcessSetMaxFiles(pid_t pid, unsigned int files);
>   int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
>   
> -int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes);
> +int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) G_GNUC_NO_INLINE;
>   
>   /* Callback to run code within the mount namespace tied to the given
>    * pid.  This function must use only async-signal-safe functions, as
> diff --git a/tests/virprocessmock.c b/tests/virprocessmock.c
> index c9386d757a..0356ff2f70 100644
> --- a/tests/virprocessmock.c
> +++ b/tests/virprocessmock.c
> @@ -21,6 +21,13 @@
>   #include <config.h>
>   #include "virprocess.h"
>   
> +int
> +virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long *bytes G_GNUC_UNUSED)

Ehm, probably coffee hadn't kicked in? Because I can see @bytes used ..

> +{
> +    *bytes = 0;

.. right here :-D

> +    return 0;
> +}
> +
>   int
>   virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long bytes G_GNUC_UNUSED)
>   {
> 

Michal

Re: [libvirt PATCH 11/17] tests: Mock virProcessGetMaxMemLock()
Posted by Andrea Bolognani 4 years, 11 months ago
On Mon, 2021-03-08 at 11:31 +0100, Michal Privoznik wrote:
> On 3/5/21 8:13 PM, Andrea Bolognani wrote:
> > +int
> > +virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long *bytes G_GNUC_UNUSED)
> 
> Ehm, probably coffee hadn't kicked in? Because I can see @bytes used ..
> 
> > +{
> > +    *bytes = 0;
> 
> .. right here :-D

More like it had been too long since the last coffee, but yeah, of
course you're absolutely right :)

-- 
Andrea Bolognani / Red Hat / Virtualization